From 2361db574853f6ec593e9a31fd32261626ded17b Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Mon, 22 Apr 2024 22:54:53 +0100 Subject: [PATCH] Enable more Ruff checks --- .ruff.toml | 32 +++++++++-------------- sphinx/domains/std/__init__.py | 2 +- sphinx/ext/autodoc/__init__.py | 2 +- sphinx/util/_pathlib.py | 4 +-- tests/test_extensions/test_ext_autodoc.py | 2 +- tests/test_util/test_util_inspect.py | 2 +- 6 files changed, 19 insertions(+), 25 deletions(-) diff --git a/.ruff.toml b/.ruff.toml index f2d45b86b..3bb00568e 100644 --- a/.ruff.toml +++ b/.ruff.toml @@ -114,9 +114,7 @@ select = [ # pycodestyle ('E') "E", # flake8-errmsg ('EM') - "EM101", # Exception must not use a string literal, assign to variable first - "EM102", # Exception must not use an f-string literal, assign to variable first - "EM103", # Exception must not use a `.format()` string directly, assign to variable first + "EM", # eradicate ('ERA') # NOT YET USED # flake8-executable ('EXE') @@ -130,7 +128,7 @@ select = [ # flake8-fixme ('FIX') # NOT YET USED # flynt ('FLY') - # NOT YET USED + "FLY", # refurb ('FURB') "FURB", # flake8-logging-format ('G') @@ -149,16 +147,11 @@ select = [ # flake8-no-pep420 ('INP') "INP", # flake8-gettext ('INT') - "INT001", # f-string is resolved before function call; consider `_("string %s") % arg` - "INT002", # `format` method argument is resolved before function call; consider `_("string %s") % arg` - "INT003", # printf-style format is resolved before function call; consider `_("string %s") % arg` + "INT", # flake8-implicit-str-concat ('ISC') # NOT YET USED # flake8-logging ('LOG') - "LOG001", # Use `logging.getLogger()` to instantiate loggers - "LOG002", # Use `__name__` with `logging.getLogger()` - "LOG007", # Use of `logging.exception` with falsy `exc_info` - "LOG009", # Use of undocumented `logging.WARN` constant + "LOG", # pep8-naming ('N') # NOT YET USED # numpy-specific rules ('NPY') @@ -186,9 +179,15 @@ select = [ "PLC0105", # `{kind}` name "{param_name}" does not reflect its {variance}; consider renaming it to "{replacement_name}" "PLC0131", # `{kind}` cannot be both covariant and contravariant "PLC0132", # `{kind}` name `{param_name}` does not match assigned variable name `{var_name}` -# "PLC0205", # Class `__slots__` should be a non-string iterable -# "PLC0208", # Use a sequence type instead of a `set` when iterating over values + "PLC0205", # Class `__slots__` should be a non-string iterable + "PLC0208", # Use a sequence type instead of a `set` when iterating over values "PLC0414", # Import alias does not rename original package +# "PLC0415", # `import` should be at the top-level of a file + "PLC1901", # `{existing}` can be simplified to `{replacement}` as an empty string is falsey + "PLC2401", # {kind} name `{name}` contains a non-ASCII character, consider renaming it + "PLC2403", # Module alias `{name}` contains a non-ASCII character, use an ASCII-only alias +# "PLC2701", # Private name import `{name}` from external module `{module}` + "PLC2801", # Unnecessary dunder call to `{method}`. {replacement}. "PLC3002", # Lambda expression called directly. Execute the expression inline instead. # pylint ('PLE') "PLE0100", # `__init__` method is a generator @@ -367,12 +366,7 @@ select = [ # pyupgrade ('UP') "UP", # pycodestyle ('W') - "W191", # Indentation contains tabs -# "W291", # Trailing whitespace - "W292", # No newline at end of file - "W293", # Blank line contains whitespace - "W505", # Doc line too long ({width} > {limit} characters) - "W605", # Invalid escape sequence: `\{char}` + "W", # flake8-2020 ('YTT') "YTT", ] diff --git a/sphinx/domains/std/__init__.py b/sphinx/domains/std/__init__.py index 30d0977a2..b2ac8bfc9 100644 --- a/sphinx/domains/std/__init__.py +++ b/sphinx/domains/std/__init__.py @@ -921,7 +921,7 @@ class StandardDomain(Domain): # * :option:`-foo=bar` # * :option:`-foo[=bar]` # * :option:`-foo bar` - for needle in {'=', '[=', ' '}: + for needle in ('=', '[=', ' '): if needle in target: stem, _, _ = target.partition(needle) docname, labelid = self.progoptions.get((progname, stem), ('', '')) diff --git a/sphinx/ext/autodoc/__init__.py b/sphinx/ext/autodoc/__init__.py index 45e4cad65..8616ecf97 100644 --- a/sphinx/ext/autodoc/__init__.py +++ b/sphinx/ext/autodoc/__init__.py @@ -170,7 +170,7 @@ def merge_members_option(options: dict) -> None: return members = options.setdefault('members', []) - for key in {'private-members', 'special-members'}: + for key in ('private-members', 'special-members'): if key in options and options[key] not in (ALL, None): for member in options[key]: if member not in members: diff --git a/sphinx/util/_pathlib.py b/sphinx/util/_pathlib.py index 8bb1f3115..628e649c7 100644 --- a/sphinx/util/_pathlib.py +++ b/sphinx/util/_pathlib.py @@ -28,7 +28,7 @@ if sys.platform == 'win32': # replace exists in both Path and str; # in Path it makes filesystem changes, so we use the safer str version warnings.warn(_MSG, RemovedInSphinx80Warning, stacklevel=2) - return self.__str__().replace(old, new, count) + return self.__str__().replace(old, new, count) # NoQA: PLC2801 def __getattr__(self, item: str) -> Any: if item in _STR_METHODS: @@ -77,7 +77,7 @@ else: # replace exists in both Path and str; # in Path it makes filesystem changes, so we use the safer str version warnings.warn(_MSG, RemovedInSphinx80Warning, stacklevel=2) - return self.__str__().replace(old, new, count) + return self.__str__().replace(old, new, count) # NoQA: PLC2801 def __getattr__(self, item: str) -> Any: if item in _STR_METHODS: diff --git a/tests/test_extensions/test_ext_autodoc.py b/tests/test_extensions/test_ext_autodoc.py index 54f81f2c2..a88d111bd 100644 --- a/tests/test_extensions/test_ext_autodoc.py +++ b/tests/test_extensions/test_ext_autodoc.py @@ -429,7 +429,7 @@ def _assert_getter_works(app, directive, objtype, name, attrs=(), **kw): hooked_members = {s[1] for s in getattr_spy} documented_members = {s[1] for s in processed_signatures} for attr in attrs: - fullname = '.'.join((name, attr)) + fullname = f'{name}.{attr}' assert attr in hooked_members assert fullname not in documented_members, f'{fullname!r} not intercepted' diff --git a/tests/test_util/test_util_inspect.py b/tests/test_util/test_util_inspect.py index 32840b82e..83a6b72d9 100644 --- a/tests/test_util/test_util_inspect.py +++ b/tests/test_util/test_util_inspect.py @@ -662,7 +662,7 @@ def test_getslots(): __slots__ = {'attr': 'docstring'} class Qux: - __slots__ = 'attr' + __slots__ = 'attr' # NoQA: PLC0205 assert inspect.getslots(Foo) is None assert inspect.getslots(Bar) == {'attr': None}