Repository navigation
0.12.0
·
26 commits
to main
since this release
Immutable
release. Only release title and notes can be modified.
Features
accumulator-loopreports a loop that only adds to a string, bytes or number started empty or at0the line before, and its unsafe fix builds the value withstr.join()orsum()(#136) by @gaborbernat.ambiguous-operator-chainreports comparison chains that mix operator kinds, such askey == value in tableora != b != c, and a bitwise operation in the middle of a chain, such asa > 1 & b < 2, which binds tighter than the comparisons around it (#136) by @gaborbernat.anchored-regex-matchreportsre.match()with a pattern anchored at its end, andre.search()with one anchored at both ends, whose$lets a trailing newline through; the fix callsre.fullmatch()without the anchors.up-re-prefixmatchleaves those calls to it when both are selected (#136) by @gaborbernat.async-sync-dunderreportsasync defon special methods Python calls without awaiting, such as__len__,__enter__and a non-generator__aiter__(#136) by @gaborbernat.broken-decorator-stackreports@propertyover@staticmethodor@classmethod, and@classmethodover@property, which stopped working in Python 3.13 (#136) by @gaborbernat.cached-generatorreportsfunctools.cache,lru_cacheorcached_propertyon a generator, whose cached generator the first caller exhausts (#136) by @gaborbernat.catastrophic-regexreports a nested repeat such as(a+)+that backtracks in exponential time on an input that almost matches (#136) by @gaborbernat.comprehension-complexityreports a comprehension with a secondforor a secondifclause, a nested loop or a compound filter that aforstatement or a named predicate states better (#136) by @gaborbernat.dead-storereports a value assigned to a local that the next assignment in the same block replaces before anything reads it, such astotal = 0right beforetotal = len(items). Its fix removes the assignment when the value is a constant (#136) by @gaborbernat.default-argument-valuereports 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 tounused-default(#136) by @gaborbernat.dropped-exception-notereports anadd_notecall on an exception that is then swallowed or never raised (#136) by @gaborbernat.duplicate-conditionreports aneliftest an earlier branch already tried, an operand repeated in oneandoror, and acasepattern an earlier case already matches, none of which changes what runs (#136) by @gaborbernat.empty-collection-comparisonreports==and!=comparisons with[],()or{}, and its unsafe fix turns the test of anif,whileor conditional expression into a truth test (#136) by @gaborbernat.exception-init-argsreports exception classes whose__init__passes its parent different positional arguments from those it takes, or requires a keyword-only one, sopickleandcopycannot rebuild them (#136) by @gaborbernat.expression-complexityreports an expression nested deeper thanlogic.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-swapreportsa = bfollowed byb = a, which leaves both holding the oldb, with an unsafe fix toa, b = b, a, and augmented assignments such astotal += total + deltathat apply their target twice (#136) by @gaborbernat.function-as-conditionreports a function tested without being called, asif is_ready:, and calls it when it takes no arguments (#136) by @gaborbernat.in-place-resultreports a stored, returned, passed or compared result of an in-place method of a list, dict or set, such asordered = names.sort(), and ofrandom.shuffle(), which is alwaysNone(#136) by @gaborbernat.iterator-reusereports amap(),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-loopreports aforloop's variable read after a loop with nobreak, where it holds the last item and is unbound when the loop never runs (#136) by @gaborbernat.misplaced-argumentsreports a call that passes variables named after parameters into other parameters' slots, leaving deliberate swaps alone (#136) by @gaborbernat.missing-overridereports 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@overridenext to thedefand imports it fromtyping(#136) by @gaborbernat.mutable-module-constantreports anUPPER_CASEorFinalmodule constant bound to a list, set or dict that no code changes, and its unsafe fix makes it a tuple, a frozenset, or afrozendictfrom Python 3.15 and aMappingProxyTypebefore 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-loopreportsfor i in range(len(seq))loops that readseq[i], and its unsafe fix loops overseqitself when the index serves only to read the items (#136) by @gaborbernat.rejected-operandreports operator methods that return a boolean or raiseTypeErrorfor an operand type they do not handle, with an unsafe fix toreturn NotImplemented(#136) by @gaborbernat.rst-unraised-exceptionreports a:raises X:field for an exception the function can no longer raise: noraisein its body or in the same-module functions and methods it calls namesXor 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-handlerreports anexceptclass 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-repetitionreports 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-expressionreports a comprehension used as a statement only for the calls in it, anda and f()ora or f()used as a statement. Its fix writes aforloop or anif(#136) by @gaborbernat.slice-affix-comparisonreportss[:n] == "..."ands[-n:] == "..."with a literal of lengthn. Whensis surely astrorbytes, its unsafe fix callsstartswith()orendswith()instead (#136) by @gaborbernat.test-process-statereports a test, fixture or test class method that changes an environment variable, the working directory,sys.path,sys.argv,sys.modulesor a module attribute by hand, which leaks into the tests that run after it;monkeypatchmakes the same change and undoes it (#136) by @gaborbernat.test-return-valuereports a test that returns a value, which pytest ignores, and its unsafe fix turns a returned comparison or boolean into theassertthe author meant (#136) by @gaborbernat.test-without-assertionreports a test with noassert, noraiseand 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-attributesreports a class whose instances hold more attributes thanclasses.max-instance-attributes, 12 by default, counting what its methods set onselfand a dataclass's fields; related attributes belong in classes of their own (#136) by @gaborbernat.unawaited-coroutinereports a call of anasync defas a statement of its own, whose body never runs, and adds the missingawaitinside a coroutine (#136) by @gaborbernat.unbound-superreports zero-argumentsuper()in generator expressions, pre-3.12 comprehensions, parameterless lambdas and nested functions, class bodies and functions outside a class (#136) by @gaborbernat.uncollected-test-modulereports a test module whose file name thepython_filespatterns do not match, such astests/check_parser.py, so pytest never runs its tests (#136) by @gaborbernat.undeclared-dependencyreports 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-argsreports a builtin exception raised with a%or{}message and the values meant to fill it, such asraise ValueError("bad %s", value), which shows a tuple instead of the message. Its unsafe fix formats the message (#136) by @gaborbernat.unreachable-codereports statements that never run: those after areturn,raise,breakorcontinue, after anifortrywhose every branch leaves, after awhile Truewith nobreak, and under anif False:orwhile 0:. Its unsafe fix deletes them (#136) by @gaborbernat.unregistered-markerreports apytest.markname that the project's pytest configuration does not register undermarkers, 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-dependencyreports a requirement in[project] dependenciesthat 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__.pyof the project's first top-level package (#136) by @gaborbernat.up-pytest-deprecated-apireports pytest APIs that pytest 8 and 9 removed or no longer honor: nose-stylesetupandteardownhooks, marks on fixtures, thetmpdir,tmpdir_factoryandtestdirfixtures,msg=topytest.fail,pytest.skipandpytest.exit,pytest.raises(message=...)andpytest.warns(None). It renamesmsgtoreason, and, as an unsafe fix, a nose hook to its pytest name (#136) by @gaborbernat.wall-clock-durationreports durations measured withtime.time(), which jumps when the system clock is set, and its fix measures them withtime.perf_counter()(#136) by @gaborbernat.wrapper-without-wrapsreports a decorator wrapper that forwards its arguments withoutfunctools.wraps, and adds the decorator (#136) by @gaborbernat.
Changes
unused-definitionalso reports nested functions their enclosing function never refers to, and instance attributes that methods store onselfbut nothing in the run reads (#136) by @gaborbernat.
Bug fixes
all-formatkeeps 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__throughgetattrand expects a tuple (#136) by @gaborbernat.single-user-constantandmodule-variable-prefixcountcast(T, module).name = valueas a write tomodule.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-nameandmodule-variable-prefixkeep 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 importsserialize_ssh_public_key(#136) by @gaborbernat.single-use-variableno longer reports a name bound to a weak reference or proxy. Inliningref = 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-classkeeps its report without a fix when another module imports the class or a string in the run names it: urllib3 importsTestSSLfrom another test module, and anyio's tests match qualified names that contain the class (#136) by @gaborbernat.unused-defaultcounts calls whose result is dropped when it matches a call to a function the import resolver cannot place, such as a script on pytest'spythonpath. It removed aiobotocore'sfull_historydefault that such a call still passed (#136) by @gaborbernat.unused-definitiontreats 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.