Skip to content

0.12.0

Choose a tag to compare

@github-actions github-actions released this 13 Nov 17:32
· 26 commits to main since this release
Immutable release. Only release title and notes can be modified.

Features

  • accumulator-loop reports a loop that only adds to a string, bytes or number started empty or at 0 the line before, and its unsafe fix builds the value with str.join() or sum() (#136) by @gaborbernat.
  • ambiguous-operator-chain reports comparison chains that mix operator kinds, such as key == value in table or a != b != c, and a bitwise operation in the middle of a chain, such as a > 1 & b < 2, which binds tighter than the comparisons around it (#136) by @gaborbernat.
  • anchored-regex-match reports re.match() with a pattern anchored at its end, and re.search() with one anchored at both ends, whose $ lets a trailing newline through; the fix calls re.fullmatch() without the anchors. up-re-prefixmatch leaves those calls to it when both are selected (#136) by @gaborbernat.
  • async-sync-dunder reports async def on special methods Python calls without awaiting, such as __len__, __enter__ and a non-generator __aiter__ (#136) by @gaborbernat.
  • broken-decorator-stack reports @property over @staticmethod or @classmethod, and @classmethod over @property, which stopped working in Python 3.13 (#136) by @gaborbernat.
  • cached-generator reports functools.cache, lru_cache or cached_property on a generator, whose cached generator the first caller exhausts (#136) by @gaborbernat.
  • catastrophic-regex reports a nested repeat such as (a+)+ that backtracks in exponential time on an input that almost matches (#136) by @gaborbernat.
  • comprehension-complexity reports a comprehension with a second for or a second if clause, a nested loop or a compound filter that a for statement or a named predicate states better (#136) by @gaborbernat.
  • dead-store reports a value assigned to a local that the next assignment in the same block replaces before anything reads it, such as total = 0 right before total = len(items). Its fix removes the assignment when the value is a constant (#136) by @gaborbernat.
  • default-argument-value reports an argument that passes a parameter of a function in the same module the literal its default already gives, as a keyword or as the last positional argument. Such an argument pins the call to today's default and suggests the value matters there. The safe fix removes it. A parameter every call passes is left to unused-default (#136) by @gaborbernat.
  • dropped-exception-note reports an add_note call on an exception that is then swallowed or never raised (#136) by @gaborbernat.
  • duplicate-condition reports an elif test an earlier branch already tried, an operand repeated in one and or or, and a case pattern an earlier case already matches, none of which changes what runs (#136) by @gaborbernat.
  • empty-collection-comparison reports == and != comparisons with [], () or {}, and its unsafe fix turns the test of an if, while or conditional expression into a truth test (#136) by @gaborbernat.
  • exception-init-args reports exception classes whose __init__ passes its parent different positional arguments from those it takes, or requires a keyword-only one, so pickle and copy cannot rebuild them (#136) by @gaborbernat.
  • expression-complexity reports an expression nested deeper than logic.max-expression-complexity, 8 by default, where each operator, comparison, call, subscript, lambda and comprehension adds a level. Naming the parts spares the reader holding every partial result in mind (#136) by @gaborbernat.
  • failed-swap reports a = b followed by b = a, which leaves both holding the old b, with an unsafe fix to a, b = b, a, and augmented assignments such as total += total + delta that apply their target twice (#136) by @gaborbernat.
  • function-as-condition reports a function tested without being called, as if is_ready:, and calls it when it takes no arguments (#136) by @gaborbernat.
  • in-place-result reports a stored, returned, passed or compared result of an in-place method of a list, dict or set, such as ordered = names.sort(), and of random.shuffle(), which is always None (#136) by @gaborbernat.
  • iterator-reuse reports a map(), zip(), generator expression or other one-pass iterator read a second time, or read inside a loop, where the read finds it empty without an error (#136) by @gaborbernat.
  • loop-variable-after-loop reports a for loop's variable read after a loop with no break, where it holds the last item and is unbound when the loop never runs (#136) by @gaborbernat.
  • misplaced-arguments reports a call that passes variables named after parameters into other parameters' slots, leaving deliberate swaps alone (#136) by @gaborbernat.
  • missing-override reports a method that overrides a method of a base class in the run, across files, without @typing.override, on Python 3.12 and later. With the decorator a type checker reports the method once the base renames or removes what it overrides. The safe fix adds @override next to the def and imports it from typing (#136) by @gaborbernat.
  • mutable-module-constant reports an UPPER_CASE or Final module constant bound to a list, set or dict that no code changes, and its unsafe fix makes it a tuple, a frozenset, or a frozendict from Python 3.15 and a MappingProxyType before it, retyping its annotation to match. The fix stays off when a read in the module depends on the type, such as == with a list or + (#136) by @gaborbernat.
  • range-len-loop reports for i in range(len(seq)) loops that read seq[i], and its unsafe fix loops over seq itself when the index serves only to read the items (#136) by @gaborbernat.
  • rejected-operand reports operator methods that return a boolean or raise TypeError for an operand type they do not handle, with an unsafe fix to return NotImplemented (#136) by @gaborbernat.
  • rst-unraised-exception reports a :raises X: field for an exception the function can no longer raise: no raise in its body or in the same-module functions and methods it calls names X or a subclass, and no operation in them raises it on its own. A body that calls code outside the module, or does anything else that can raise an arbitrary exception, is left alone. The unsafe fix removes the field (#136) by @gaborbernat.
  • shadowed-except-handler reports an except class that an earlier handler or the same tuple already catches through a base class, with a safe fix that drops a redundant tuple entry (#136) by @gaborbernat.
  • shared-mutable-repetition reports a list or tuple repeated with * whose element is a mutable object, such as [[0] * n] * m, when the code then changes an element through the name it is stored in, which changes every copy. Its unsafe fix builds the element in a comprehension (#136) by @gaborbernat.
  • side-effect-expression reports a comprehension used as a statement only for the calls in it, and a and f() or a or f() used as a statement. Its fix writes a for loop or an if (#136) by @gaborbernat.
  • slice-affix-comparison reports s[:n] == "..." and s[-n:] == "..." with a literal of length n. When s is surely a str or bytes, its unsafe fix calls startswith() or endswith() instead (#136) by @gaborbernat.
  • test-process-state reports a test, fixture or test class method that changes an environment variable, the working directory, sys.path, sys.argv, sys.modules or a module attribute by hand, which leaks into the tests that run after it; monkeypatch makes the same change and undoes it (#136) by @gaborbernat.
  • test-return-value reports a test that returns a value, which pytest ignores, and its unsafe fix turns a returned comparison or boolean into the assert the author meant (#136) by @gaborbernat.
  • test-without-assertion reports a test with no assert, no raise and no call that can fail it, following the module's own helpers, so it passes for any code that does not raise. A test whose name, docstring or comments say it checks for crashes or errors is left alone (#136) by @gaborbernat.
  • too-many-attributes reports a class whose instances hold more attributes than classes.max-instance-attributes, 12 by default, counting what its methods set on self and a dataclass's fields; related attributes belong in classes of their own (#136) by @gaborbernat.
  • unawaited-coroutine reports a call of an async def as a statement of its own, whose body never runs, and adds the missing await inside a coroutine (#136) by @gaborbernat.
  • unbound-super reports zero-argument super() in generator expressions, pre-3.12 comprehensions, parameterless lambdas and nested functions, class bodies and functions outside a class (#136) by @gaborbernat.
  • uncollected-test-module reports a test module whose file name the python_files patterns do not match, such as tests/check_parser.py, so pytest never runs its tests (#136) by @gaborbernat.
  • undeclared-dependency reports an import of a third-party module that no requirement or extra in [project] installs, in the modules that run when the package is imported. Such an import works where a development tool or another package installed the module and fails for a user who installs only what the project lists. Plugin modules, tests, and guarded, deferred or version-dependent imports are left alone (#136) by @gaborbernat.
  • unformatted-exception-args reports a builtin exception raised with a % or {} message and the values meant to fill it, such as raise ValueError("bad %s", value), which shows a tuple instead of the message. Its unsafe fix formats the message (#136) by @gaborbernat.
  • unreachable-code reports statements that never run: those after a return, raise, break or continue, after an if or try whose every branch leaves, after a while True with no break, and under an if False: or while 0:. Its unsafe fix deletes them (#136) by @gaborbernat.
  • unregistered-marker reports a pytest.mark name that the project's pytest configuration does not register under markers, so a misspelled mark that pytest only warns about is caught before the run. It reads the same configuration files pytest does (#136) by @gaborbernat.
  • unused-dependency reports a requirement in [project] dependencies that no file of the run outside the tests imports. Every user installs it for nothing, and one the tests alone import belongs in a dependency group. The reports sit at the start of the __init__.py of the project's first top-level package (#136) by @gaborbernat.
  • up-pytest-deprecated-api reports pytest APIs that pytest 8 and 9 removed or no longer honor: nose-style setup and teardown hooks, marks on fixtures, the tmpdir, tmpdir_factory and testdir fixtures, msg= to pytest.fail, pytest.skip and pytest.exit, pytest.raises(message=...) and pytest.warns(None). It renames msg to reason, and, as an unsafe fix, a nose hook to its pytest name (#136) by @gaborbernat.
  • wall-clock-duration reports durations measured with time.time(), which jumps when the system clock is set, and its fix measures them with time.perf_counter() (#136) by @gaborbernat.
  • wrapper-without-wraps reports a decorator wrapper that forwards its arguments without functools.wraps, and adds the decorator (#136) by @gaborbernat.

Changes

  • unused-definition also reports nested functions their enclosing function never refers to, and instance attributes that methods store on self but nothing in the run reads (#136) by @gaborbernat.

Bug fixes

  • all-format keeps reporting a tuple __all__ but no longer offers its fix when a test module mentions __all__ or another module imports it: anyio's suite reads every __all__ through getattr and expects a tuple (#136) by @gaborbernat.
  • single-user-constant and module-variable-prefix count cast(T, module).name = value as a write to module.name, so they no longer move or rename a variable another module sets that way, as fastapi's tests set a tutorial module's file path (#136) by @gaborbernat.
  • module-variable-case, unexported-public-name and module-variable-prefix keep their reports without a rename fix in a project built with maturin or setuptools-rust, whose native code imports Python names simplint cannot see, as cryptography's Rust code imports serialize_ssh_public_key (#136) by @gaborbernat.
  • single-use-variable no longer reports a name bound to a weak reference or proxy. Inlining ref = weakref.ref(obj) into its one use lets the reference die at once, so code that counts weak references, as pycparser's tests do, sees none (#136) by @gaborbernat.
  • test-class keeps its report without a fix when another module imports the class or a string in the run names it: urllib3 imports TestSSL from another test module, and anyio's tests match qualified names that contain the class (#136) by @gaborbernat.
  • unused-default counts calls whose result is dropped when it matches a call to a function the import resolver cannot place, such as a script on pytest's pythonpath. It removed aiobotocore's full_history default that such a call still passed (#136) by @gaborbernat.
  • unused-definition treats a class that defines __getnewargs__ or __getnewargs_ex__ as read whole, as it already did for __reduce__: pickle rebuilds such objects through those hooks (#136) by @gaborbernat.

🐍 PyPI release

📜 Full Changelog