Flake8-pyi

Latest version: v24.9.0

Safety actively analyzes 706267 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

Page 2 of 7

24.1.0

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](https://peps.python.org/pep-0570/) 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

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`](https://peps.python.org/pep-0673/#valid-locations-for-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

* 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

Features:
* Support Python 3.12
* Support [PEP 695](https://peps.python.org/pep-0695/) 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](https://peps.python.org/pep-0688/) 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](https://github.com/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.

23.5.0

* flake8-pyi no longer supports being run with flake8 <5.0.4.
* The way in which flake8-pyi modifies pyflakes runs has been improved:
* When flake8-pyi is installed, pyflakes now correctly recognises an annotation as
being equivalent to a binding assignment in a stub file, reducing false
positives from flake8's F821 error code.
* When flake8-pyi is installed, there are now fewer pyflakes positives from class
definitions that have forward references in the bases tuple for the purpose of
creating recursive or circular type definitions. These are invalid in `.py` files,
but are supported in stub files.
* When flake8-pyi is installed, pyflakes will also *complain* about code which (in
combination with flake8-pyi) it previously had no issue with. For example, it will
now complain about this code:

py
class Foo(Bar): ...
class Bar: ...


Although the above code is legal in a stub file, it is considered poor style, and
the forward reference serves no purpose (there is no recursive or circular
definition). As such, it is now disallowed by pyflakes when flake8-pyi is
installed.

Contributed by [tomasr8](https://github.com/tomasr8).
* Introduce Y056: Various type checkers have different levels of support for method
calls on `__all__`. Use `__all__ += ["foo", "bar"]` instead, as this is known to be
supported by all major type checkers.

23.4.1

New error codes:
* Y055: Unions of the form `type[X] | type[Y]` can be simplified to `type[X | Y]`.
Similarly, `Union[type[X], type[Y]]` can be simplified to `type[Union[X, Y]]`.
Contributed by [tomasr8](https://github.com/tomasr8).

Page 2 of 7

© 2025 Safety CLI Cybersecurity Inc. All Rights Reserved.