Enable more Ruff checks

This commit is contained in:
Adam Turner 2024-04-22 22:54:53 +01:00
parent 80ac07907d
commit 2361db5748
6 changed files with 19 additions and 25 deletions

View File

@ -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",
]

View File

@ -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), ('', ''))

View File

@ -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:

View File

@ -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:

View File

@ -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'

View File

@ -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}