From 6df3cfc6e330d4ec4176694f9ccd8c3c027d8532 Mon Sep 17 00:00:00 2001 From: Ilya Simpson Date: Tue, 22 Jul 2025 15:17:46 +1200 Subject: [PATCH] Enable `flake8-unused-arguments` Ruff rule. --- pelican/__init__.py | 2 ++ pelican/contents.py | 3 ++- pelican/generators.py | 3 +++ pelican/readers.py | 10 ++++++---- pelican/rstdirectives.py | 1 + pelican/tests/test_contents.py | 2 +- pelican/tests/test_importer.py | 6 +++--- pelican/tests/test_server.py | 2 +- pelican/tools/pelican_import.py | 1 - pelican/utils.py | 8 +++----- pyproject.toml | 2 +- 11 files changed, 23 insertions(+), 17 deletions(-) diff --git a/pelican/__init__.py b/pelican/__init__.py index 0e92def9..8d916fc7 100644 --- a/pelican/__init__.py +++ b/pelican/__init__.py @@ -252,6 +252,7 @@ class Pelican: class PrintSettings(argparse.Action): def __call__(self, parser, namespace, values, option_string): + del option_string # Unused argument init_logging(name=__name__) try: @@ -287,6 +288,7 @@ class PrintSettings(argparse.Action): class ParseOverrides(argparse.Action): def __call__(self, parser, namespace, values, option_string=None): + del parser, option_string # Unused arguments overrides = {} for item in values: try: diff --git a/pelican/contents.py b/pelican/contents.py index daf72ce6..a06a1a6a 100644 --- a/pelican/contents.py +++ b/pelican/contents.py @@ -431,7 +431,7 @@ class Content: return self.get_content(self.get_siteurl()) @memoized - def get_summary(self, siteurl: str) -> str: + def get_summary(self, _siteurl: str) -> str: """Returns the summary of an article. This is based on the summary metadata if set, otherwise truncate the @@ -552,6 +552,7 @@ class SkipStub(Content): def __init__( self, content, metadata=None, settings=None, source_path=None, context=None ): + del content, metadata, settings, context # Unused arguments self.source_path = source_path def is_valid(self): diff --git a/pelican/generators.py b/pelican/generators.py index 0e6b08ea..e04d1733 100644 --- a/pelican/generators.py +++ b/pelican/generators.py @@ -296,6 +296,7 @@ class _FileLoader(BaseLoader): self.fullpath = os.path.join(basedir, path) def get_source(self, environment, template): + del environment # Unused argument if template != self.path or not os.path.exists(self.fullpath): raise TemplateNotFound(template) mtime = os.path.getmtime(self.fullpath) @@ -1022,6 +1023,7 @@ class StaticGenerator(Generator): signals.static_generator_finalized.send(self) def generate_output(self, writer): + del writer # Unused argument self._copy_paths( self.settings["THEME_STATIC_PATHS"], self.theme, @@ -1131,6 +1133,7 @@ class SourceFileGenerator(Generator): copy(obj.source_path, dest) def generate_output(self, writer=None): + del writer # Unused argument logger.info("Generating source files...") for obj in chain(self.context["articles"], self.context["pages"]): self._create_source(obj) diff --git a/pelican/readers.py b/pelican/readers.py index fc0a4f40..ca1b2393 100644 --- a/pelican/readers.py +++ b/pelican/readers.py @@ -45,15 +45,15 @@ DUPLICATES_DEFINITIONS_ALLOWED = { METADATA_PROCESSORS = { "tags": lambda x, y: ([Tag(tag, y) for tag in ensure_metadata_list(x)] or _DISCARD), - "date": lambda x, y: get_date(x.replace("_", " ")), - "modified": lambda x, y: get_date(x), - "status": lambda x, y: x.strip() or _DISCARD, + "date": lambda x, _y: get_date(x.replace("_", " ")), + "modified": lambda x, _y: get_date(x), + "status": lambda x, _y: x.strip() or _DISCARD, "category": lambda x, y: _process_if_nonempty(Category, x, y), "author": lambda x, y: _process_if_nonempty(Author, x, y), "authors": lambda x, y: ( [Author(author, y) for author in ensure_metadata_list(x)] or _DISCARD ), - "slug": lambda x, y: x.strip() or _DISCARD, + "slug": lambda x, _y: x.strip() or _DISCARD, } logger = logging.getLogger(__name__) @@ -121,6 +121,7 @@ class BaseReader: def read(self, source_path): "No-op parser" + del source_path # Unused argument content = None metadata = {} return content, metadata @@ -165,6 +166,7 @@ class PelicanHTMLTranslator(HTMLTranslator): self.body.append(self.starttag(node, "abbr", "", **attrs)) def depart_abbreviation(self, node): + del node # Unused argument self.body.append("") def visit_image(self, node): diff --git a/pelican/rstdirectives.py b/pelican/rstdirectives.py index 9022ac83..e45a0582 100644 --- a/pelican/rstdirectives.py +++ b/pelican/rstdirectives.py @@ -79,6 +79,7 @@ class abbreviation(nodes.Inline, nodes.TextElement): def abbr_role(typ, rawtext, text, lineno, inliner, options=None, content=None): + del typ, rawtext, lineno, inliner, options, content # Unused arguments text = utils.unescape(text) m = _abbr_re.search(text) if m is None: diff --git a/pelican/tests/test_contents.py b/pelican/tests/test_contents.py index 3c3aae81..4b1effa2 100644 --- a/pelican/tests/test_contents.py +++ b/pelican/tests/test_contents.py @@ -333,7 +333,7 @@ class TestPage(TestBase): self.assertEqual("custom", custom_page.template) def test_signal(self): - def receiver_test_function(sender): + def receiver_test_function(_sender): receiver_test_function.has_been_called = True receiver_test_function.has_been_called = False diff --git a/pelican/tests/test_importer.py b/pelican/tests/test_importer.py index 10b0f7f6..2df56e0d 100644 --- a/pelican/tests/test_importer.py +++ b/pelican/tests/test_importer.py @@ -552,7 +552,7 @@ class TestWordpressXMLAttachements(TestCaseWithCLocale): class TestTumblrImporter(TestCaseWithCLocale): @patch("pelican.tools.pelican_import._get_tumblr_posts") def test_posts(self, get): - def get_posts(api_key, blogname, offset=0): + def get_posts(_api_key, _blogname, offset=0): if offset > 0: return [] @@ -603,7 +603,7 @@ class TestTumblrImporter(TestCaseWithCLocale): @patch("pelican.tools.pelican_import._get_tumblr_posts") def test_video_embed(self, get): - def get_posts(api_key, blogname, offset=0): + def get_posts(_api_key, _blogname, offset=0): if offset > 0: return [] @@ -657,7 +657,7 @@ class TestTumblrImporter(TestCaseWithCLocale): @patch("pelican.tools.pelican_import._get_tumblr_posts") def test_broken_video_embed(self, get): - def get_posts(api_key, blogname, offset=0): + def get_posts(_api_key, _blogname, offset=0): if offset > 0: return [] diff --git a/pelican/tests/test_server.py b/pelican/tests/test_server.py index fd616ef7..43cd070d 100644 --- a/pelican/tests/test_server.py +++ b/pelican/tests/test_server.py @@ -8,7 +8,7 @@ from pelican.tests.support import unittest class MockRequest: - def makefile(self, *args, **kwargs): + def makefile(self, *_args, **_kwargs): return BytesIO(b"") diff --git a/pelican/tools/pelican_import.py b/pelican/tools/pelican_import.py index d0f2b3c2..bd349ac9 100755 --- a/pelican/tools/pelican_import.py +++ b/pelican/tools/pelican_import.py @@ -941,7 +941,6 @@ def fields2pelican( strip_raw=False, disable_slugs=False, dirpage=False, - filename_template=None, filter_author=None, wp_custpost=False, wp_attach=False, diff --git a/pelican/utils.py b/pelican/utils.py index 5531d2fb..eb281ce9 100644 --- a/pelican/utils.py +++ b/pelican/utils.py @@ -8,7 +8,6 @@ import os import pathlib import re import shutil -import sys import traceback import unicodedata import urllib @@ -215,7 +214,7 @@ def deprecated_attribute( _warn() setattr(self, new, value) - def decorator(dummy): + def decorator(_dummy): return property(fget=fget, fset=fset, doc=doc) return decorator @@ -235,9 +234,7 @@ def get_date(string: str) -> datetime.datetime: @contextmanager -def pelican_open( - filename: str, mode: str = "r", strip_crs: bool = (sys.platform == "win32") -) -> Generator[str, None, None]: +def pelican_open(filename: str, mode: str = "r") -> Generator[str, None, None]: """Open a file and return its content""" # utf-8-sig will clear any BOM if present @@ -493,6 +490,7 @@ class _HTMLWordTruncator(HTMLParser): self.add_word(self.last_word_end) def handle_starttag(self, tag: str, attrs: Any) -> None: + del attrs # Unused argument self.add_last_word() if tag not in self._singlets: self.open_tags.insert(0, tag) diff --git a/pyproject.toml b/pyproject.toml index f92509f8..8d0fd9b9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -125,7 +125,7 @@ select = [ # the rest in alphabetical order: "A", # flake8-builtins - # TODO: "ARG", # flake8-unused-arguments + "ARG", # flake8-unused-arguments "B", # flake8-bugbear # TODO: "BLE", # flake8-blind-except # TODO: Do I want "COM", # flake8-commas