From 82b48fcfa12a0fc02c82172f47440870de10ead2 Mon Sep 17 00:00:00 2001 From: boxydog Date: Fri, 31 May 2024 10:41:24 -0500 Subject: [PATCH] Fixes in files for ruff T201, RUF001, PLR2004, B904, SLOT000, PYI024, PIE800 --- docs/conf.py | 2 +- pelican/__init__.py | 4 ++-- pelican/generators.py | 2 +- pelican/paginator.py | 2 +- pelican/server.py | 14 ++++++-------- pelican/tests/test_importer.py | 4 ++-- pelican/tools/pelican_quickstart.py | 2 +- pelican/utils.py | 8 ++++---- 8 files changed, 18 insertions(+), 20 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 8d8078a27..8f14a0187 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -29,7 +29,7 @@ master_doc = "index" project = project_data.get("name").upper() year = datetime.datetime.now().date().year -copyright = f"2010–{year}" +copyright = f"2010–{year}" # noqa: RUF001 exclude_patterns = ["_build"] release = project_data.get("version") version = ".".join(release.split(".")[:1]) diff --git a/pelican/__init__.py b/pelican/__init__.py index ab6b0225f..20d177063 100644 --- a/pelican/__init__.py +++ b/pelican/__init__.py @@ -294,7 +294,7 @@ def __call__(self, parser, namespace, values, option_string=None): raise ValueError( "Extra settings must be specified as KEY=VALUE pairs " f"but you specified {item}" - ) + ) from None try: overrides[k] = json.loads(v) except json.decoder.JSONDecodeError: @@ -305,7 +305,7 @@ def __call__(self, parser, namespace, values, option_string=None): "Use -e KEY='\"string\"' to specify a string value; " "-e KEY=null to specify None; " "-e KEY=false (or true) to specify False (or True)." - ) + ) from None setattr(namespace, self.dest, overrides) diff --git a/pelican/generators.py b/pelican/generators.py index fdcc62ce4..a2bf2f448 100644 --- a/pelican/generators.py +++ b/pelican/generators.py @@ -1040,7 +1040,7 @@ def _source_is_newer(self, staticfile): save_as = os.path.join(self.output_path, staticfile.save_as) s_mtime = os.path.getmtime(source_path) d_mtime = os.path.getmtime(save_as) - return s_mtime - d_mtime > 0.000001 + return s_mtime - d_mtime > 0.000001 # noqa: PLR2004 def _link_or_copy_staticfile(self, sc): if self.settings["STATIC_CREATE_LINKS"]: diff --git a/pelican/paginator.py b/pelican/paginator.py index 92cb26b17..4a7c1aa2f 100644 --- a/pelican/paginator.py +++ b/pelican/paginator.py @@ -5,7 +5,7 @@ from math import ceil logger = logging.getLogger(__name__) -PaginationRule = namedtuple( +PaginationRule = namedtuple( # noqa: PYI024 "PaginationRule", "min_page URL SAVE_AS", ) diff --git a/pelican/server.py b/pelican/server.py index 71cd2d810..ebf13677e 100644 --- a/pelican/server.py +++ b/pelican/server.py @@ -53,14 +53,12 @@ class ComplexHTTPRequestHandler(server.SimpleHTTPRequestHandler): extensions_map = { **server.SimpleHTTPRequestHandler.extensions_map, - **{ - # web fonts - ".oft": "font/oft", - ".sfnt": "font/sfnt", - ".ttf": "font/ttf", - ".woff": "font/woff", - ".woff2": "font/woff2", - }, + # web fonts + ".oft": "font/oft", + ".sfnt": "font/sfnt", + ".ttf": "font/ttf", + ".woff": "font/woff", + ".woff2": "font/woff2", } def translate_path(self, path): diff --git a/pelican/tests/test_importer.py b/pelican/tests/test_importer.py index b00970f4a..0349a175e 100644 --- a/pelican/tests/test_importer.py +++ b/pelican/tests/test_importer.py @@ -376,7 +376,7 @@ def r(f): test_post = filter(lambda p: p[0].startswith("Post with raw data"), self.posts) with temporary_folder() as temp: md = next(r(f) for f in silent_f2p(test_post, "markdown", temp)) - escaped_quotes = re.search(r'\\[\'"“”‘’]', md) + escaped_quotes = re.search(r'\\[\'"“”‘’]', md) # noqa: RUF001 self.assertFalse(escaped_quotes) def test_convert_caption_to_figure(self): @@ -505,7 +505,7 @@ def setUp(self): def test_recognise_attachments(self): self.assertTrue(self.attachments) - self.assertTrue(len(self.attachments.keys()) == 3) + self.assertEqual(3, len(self.attachments.keys())) def test_attachments_associated_with_correct_post(self): self.assertTrue(self.attachments) diff --git a/pelican/tools/pelican_quickstart.py b/pelican/tools/pelican_quickstart.py index 2f62e4bc9..9be107d08 100755 --- a/pelican/tools/pelican_quickstart.py +++ b/pelican/tools/pelican_quickstart.py @@ -79,7 +79,7 @@ # Create a 'marked' default path, to determine if someone has supplied # a path on the command-line. -class _DEFAULT_PATH_TYPE(str): +class _DEFAULT_PATH_TYPE(str): # noqa: SLOT000 is_default_path = True diff --git a/pelican/utils.py b/pelican/utils.py index 43acdd7fb..6dc4825e0 100644 --- a/pelican/utils.py +++ b/pelican/utils.py @@ -81,7 +81,7 @@ def strip_zeros(x): # test for valid C89 directives only if candidate[-1] in c89_directives: # check for '-' prefix - if len(candidate) == 3: + if len(candidate) == 3: # noqa: PLR2004 # '-' prefix candidate = f"%{candidate[-1]}" conversion = strip_zeros @@ -232,7 +232,7 @@ def get_date(string: str) -> datetime.datetime: try: return dateutil.parser.parse(string, default=default) except (TypeError, ValueError): - raise ValueError(f"{string!r} is not a valid date") + raise ValueError(f"{string!r} is not a valid date") from None @contextmanager @@ -666,13 +666,13 @@ def process_translations( raise TypeError( f"Cannot unpack {translation_id}, 'translation_id' must be falsy, a" " string or a collection of strings" - ) + ) from None except AttributeError: raise AttributeError( f"Cannot use {translation_id} as 'translation_id', there " "appear to be items without these metadata " "attributes" - ) + ) from None for id_vals, items in groupby(content_list, attrgetter(*translation_id)): # prepare warning string