Skip to content

Releases: PyCQA/flake8-pyi

24.9.0

23 Sep 18:48
33c8d9d
Compare
Choose a tag to compare

Bugfixes:

  • Don't emit Y053 for long strings inside Literal slices or metadata strings inside Annotated slices.

Other changes:

  • flake8-pyi no longer supports being run using Python 3.8. As a result, it not longer depends on the third-party ast_decompiler package.

24.6.0

12 Jun 10:18
f99a1b1
Compare
Choose a tag to compare

Bugfixes

  • Allow the use of typing_extensions.TypeVar in stubs. typing_extensions.TypeVar has the default parameter, which only exists on Python 3.13+ when using typing.TypeVar.
  • Reduce false positives from Y052 in relation to enum subclasses.

Other changes

  • Declare support for Python 3.13

24.4.1

19 Apr 16:08
f60d7e3
Compare
Choose a tag to compare

New error codes:

  • Y066: When using if/else with sys.version_info, put the code for new Python versions first.

24.4.0

11 Apr 11:21
4aaa22d
Compare
Choose a tag to compare

Bugfixes:

  • Fix Y026 false positive: allow simple assignment to None in class scopes if the class is known to be an enum class.

24.3.1

30 Mar 12:48
bf6f6f6
Compare
Choose a tag to compare

New error codes:

  • Y064: Use simpler syntax to define final literal types. For example, use x: Final = 42 instead of x: Final[Literal[42]]
  • Y065: Don't use bare Incomplete in parameter and return annotations.

Bugfixes:

  • Y090: Fix false positive for tuple[Unpack[Ts]].

24.3.0

10 Mar 13:37
0dba563
Compare
Choose a tag to compare

New error codes:

24.1.0

05 Jan 20:39
045c5e9
Compare
Choose a tag to compare

New error codes:

  • Y062: Disallow duplicate elements inside Literal[] slices.

Other features:

  • Support flake8>=7.0.0
  • Y061 is no longer emitted in situations where Y062 would also be emitted.
  • Improve error message for Y060.
  • Y023 now bans more imports from typing_extensions now that typeshed has dropped support for Python 3.7.

Bugfixes:

  • Y016: Fix false positive if a method had positional-only parameters using PEP 570 syntax and the first positional-or-keyword parameter following the positional-only parameters used a custom TypeVar (see #455).
  • Y046: Fix false negative where an unused protocol would not be detected if the protocol was generic.

23.11.0

08 Nov 15:11
06151b7
Compare
Choose a tag to compare

New error codes:

  • Y058: Use Iterator rather than Generator as the return value for simple __iter__ methods, and AsyncIterator rather than AsyncGenerator as the return value for simple __aiter__ methods.
  • Y059: Generic[] should always be the last base class, if it is present in the bases of a class.
  • Y060, which flags redundant inheritance from Generic[].
  • Y061: Do not use None inside a Literal[] slice. For example, use Literal["foo"] | None instead of Literal["foo", None].

Other changes:

  • The undocumented pyi.__version__ and pyi.PyiTreeChecker.version attributes has been removed. Use flake8 --version from the command line, or importlib.metadata.version("flake8_pyi") at runtime, to determine the version of flake8-pyi installed at runtime.
  • Y038 now flags from typing_extensions import AbstractSet as well as from typing import AbstractSet.
  • Y022 and Y037 now flag more imports from typing_extensions.
  • Y034 now attempts to avoid flagging methods inside classes that inherit from builtins.type, abc.ABCMeta and/or enum.EnumMeta. Classes that have one or more of these as bases are metaclasses, and PEP 673 forbids the use of typing(_extensions).Self for metaclasses. While reliably determining whether a class is a metaclass in all cases would be impossible for flake8-pyi, the new heuristics should reduce the number of false positives from this check.
  • Attempting to import typing_extensions.Text now causes Y039 to be emitted rather than Y023.
  • Y053 will no longer be emitted for the argument to @typing_extensions.deprecated.

23.10.0

13 Oct 09:05
56fc496
Compare
Choose a tag to compare
  • Introduce Y090, which warns if you have an annotation such as tuple[int] or Tuple[int]. These mean "a tuple of length 1, in which the sole element is of type int". This is sometimes what you want, but more usually you'll want tuple[int, ...], which means "a tuple of arbitrary (possibly 0) length, in which all elements are of type int".

    This error code is disabled by default due to the risk of false-positive errors. To enable it, use the --extend-select=Y090 option.

  • Y011 now ignores sentinel and _typeshed.sentinel in default values.

23.6.0

28 Jun 12:56
dc1eb0c
Compare
Choose a tag to compare

Features:

  • Support Python 3.12
  • Support PEP 695 syntax for declaring type aliases
  • Correctly emit Y019 errors for PEP-695 methods that are generic around a TypeVar instead of returning typing_extensions.Self
  • Introduce Y057: Do not use typing.ByteString or collections.abc.ByteString. These types have unclear semantics, and are deprecated; use typing_extensions.Buffer or a union such as bytes | bytearray | memoryview instead. See PEP 688 for more details.
  • The way in which flake8-pyi modifies pyflakes runs has been improved:
    • When flake8-pyi is installed, pyflakes will now complain about forward references in default values for function and method parameters (the same as pyflakes does when it checks .py files). Unlike in .py files, forward references in default values are legal in stub files. However, they are never necessary, and are considered bad style. (Forward references for parameter annotations are still allowed.)

      Contributed by tomasr8.

    • When flake8-pyi is installed, pyflakes's F822 check now produces many fewer false positives when flake8 is run on .pyi files. It now understands that x: int in a stub file is sufficient for x to be considered "bound", and that "x" can therefore be included in __all__.

Bugfixes:

  • Y018, Y046, Y047 and Y049 previously failed to detect unused TypeVars/ParamSpecs/TypeAliases/TypedDicts/Protocols if the object in question had multiple definitions in the same file (e.g. across two branches of an if sys.version_info >= (3, 10) check). This bug has now been fixed.
  • Y020 was previously not emitted if quoted annotations were used in TypeVar constraints. This bug has now been fixed.

Other changes:

  • flake8-pyi no longer supports being run on Python 3.7, which has reached its end of life.
  • flake8-pyi no longer supports being run with flake8 <v6.