Skip to content

Latest commit

 

History

History
685 lines (465 loc) · 22.5 KB

File metadata and controls

685 lines (465 loc) · 22.5 KB

Changelog

flake8-pyi uses Calendar Versioning (CalVer).

Unreleased

Breaking Changes

  • Previously, flake8-pyi monkey patched flake8's F821 (undefined name) check to avoid false positives in stub files. This monkey patch has been removed. Instead, we now recommend to disable F821 when running flake8 on stub files.
  • Remove the now unnecessary --no-pyi-aware-file-checker option.

New Error Codes

  • Y068: Don't use @override in stub files

Other changes

  • Drop support for Python 3.9

25.5.0

New Error Codes

  • Y067: Don't use Incomplete | None = None
  • Y091: Protocol method parameters should not be positional-or-keyword

Changed Error Codes

  • Y011, Y015: These checks will now allow all defaults that include an attribute access, for example math.inf or enum members.

Other Changes

  • Development-only dependencies are now declared using dependency groups rather than optional dependencies.
  • The plugin now exists as a flake8_pyi package rather than a single pyi.py file.
  • Declare support for Python 3.14

24.9.0

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

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

New Error Codes

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

24.4.0

Bugfixes

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

24.3.1

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

New Error Codes

24.1.0

New Error Codes

  • Y062: Disallow duplicate elements inside Literal[] slices

Changed Error Codes

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

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.

Other Changes

  • Support flake8>=7.0.0.

23.11.0

Breaking 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.

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: Redundant inheritance from Generic[]
  • Y061: Do not use None inside a Literal[] slice. For example, use Literal["foo"] | None instead of Literal["foo", None]

Changed Error Codes

  • Y038: This check now flags from typing_extensions import AbstractSet as well as from typing import AbstractSet.
  • Y022, Y037: These checks now flag more imports from typing_extensions.
  • Y034: This check 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.
  • Y053: This will no longer be emitted for the argument to @typing_extensions.deprecated.
  • Attempting to import typing_extensions.Text now causes Y039 to be emitted rather than Y023.

23.10.0

New Error Codes

  • Y090: This check 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.

Changed Error Codes

  • Y011: This check now ignores sentinel and _typeshed.sentinel in default values.

23.6.0

New Error Codes

  • 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.

Bugfixes

  • Y018, Y046, Y047, Y049: These checks 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.
  • Y019: Correctly emit errors for PEP-695 methods that are generic around a TypeVar instead of returning typing_extensions.Self.
  • Y020: This was previously not emitted if quoted annotations were used in TypeVar constraints. This bug has now been fixed.
  • Support PEP 695 syntax for declaring type aliases.
  • Support Python 3.12.

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.
  • 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__.

23.5.0

New Error Codes

  • 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.

Other Changes

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

      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.)

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).

23.4.0

Other Changes

  • Y019, Y034: Update error messages for these checks to recommend using typing_extensions.Self rather than _typeshed.Self.

23.3.1

New Error Codes

  • Y053: Disallow string or bytes literals with length >50 characters. Previously this rule only applied to parameter default values; it now applies everywhere.
  • Y054: Disallow numeric literals with a string representation >10 characters long. Previously this rule only applied to parameter default values; it now applies everywhere.

Changed Error Codes

  • Y011, Y014, Y015: Simple container literals (list, dict, tuple and set literals) are now allowed as default values.
  • Y052: This is now emitted more consistently.
  • Some things that used to result in Y011, Y014 or Y015 being emitted now result in Y053 or Y054 being emitted.

23.3.0

Changed Error Codes

  • Y011, Y014, Y015: Allow math constants math.inf, math.nan, math.e, math.pi, math.tau, and their negatives in default values. Some other semantically equivalent values, such as x = inf (from math import inf), or x = np.inf (import numpy as np), should be rewritten to x = math.inf. (Contributed by XuehaiPan.)

23.1.2

Changed Error Codes

  • Y011, Y014, Y015: Increase the maximum character length of literal numbers in default values from 7 to 10, allowing hexadecimal representation of 32-bit integers. (Contributed by Avasam.)

23.1.1

New Error Codes

  • Y052: Disallow default values in global or class namespaces where the assignment does not have a type annotation. Stubs should be explicit about the type of all variables in the stub; without type annotations, the type checker is forced to make inferences, which may have unpredictable consequences. Enum members are excluded from this check, as are various special assignments such as __all__ and __match_args__.

Changed Error Codes

  • Y020: Fewer false positives are now emitted when encountering default values in stub files.

Other Changes

  • Disallow numeric default values where len(str(default)) > 7. If a function has a default value where the string representation is greater than 7 characters, it is likely to be an implementation detail or a constant that varies depending on the system you're running on, such as sys.maxsize.
  • Disallow str or bytes defaults where the default is >50 characters long, for similar reasons.
  • Allow ast.Attribute nodes as default values for a small number of special cases, such as sys.maxsize and sys.executable.

23.1.0

Removed Error Codes

  • Y027: Prefer stdlib classes over typing aliases

Changed Error Codes

  • Y011, Y014, Y015: These checks have been significantly relaxed. None, bools, ints, floats, complex numbers, strings and bytes are all now allowed as default values for parameter annotations or assignments.
  • Y020: Do not emit Y020 (quoted annotations) for strings in parameter defaults.
  • Y022: All errors that used to result in Y027 being emitted now result in Y022 being emitted instead.
  • Y022: Some errors that used to result in Y023 being emitted now result in Y022 being emitted instead.
  • Y022: typing.Match and typing.Pattern have been added to the list of banned imports Use re.Match and re.Pattern instead.
  • Y036: Modify the check so that _typeshed.Unused is allowed as an annotation for parameters in __(a)exit__ methods. Contributed by Avasam

Bugfixes

  • Fix checking of defaults for functions with positional-only parameters.

Other Changes

  • flake8-pyi no longer supports stub files that aim to support Python 2. If your stubs need to support Python 2, pin flake8-pyi to 22.11.0 or lower.
  • Hatchling is now used as the build backend. This should have minimal, if any, user-facing impact.

22.11.0

Changed Error Codes

  • Y041: Significant changes have been made to the check. Previously, Y041 flagged "redundant numeric unions" (e.g. float | int, complex | float or complex | int) in all contexts outside of type aliases. This was incorrect. PEP 484 only specifies that type checkers should treat int as an implicit subtype of float in the specific context of parameter annotations for functions and methods. Y041 has therefore been revised to only emit errors on "redundant numeric unions" in the context of parameter annotations.

Bugfixes

  • Specify encoding when opening files. Prevents UnicodeDecodeError on Windows when the file contains non-CP1252 characters. Contributed by Avasam.

Other Changes

  • Support running with flake8 v6.

22.10.0

Bugfixes

  • Do not emit Y020 for empty strings. Y020 concerns "quoted annotations", but an empty string can never be a quoted annotation.
  • Add special-casing so that Y020 is not emitted for __slots__ definitions inside class blocks.
  • Expand Y035 to cover __slots__ definitions as well as __match_args__ and __all__ definitions.
  • Expand Y015 so that errors are emitted for assignments to negative numbers.

Other Changes

  • Since v22.8.1, flake8-pyi has emitted a FutureWarning if run with flake8<5, warning that the plugin would soon become incompatible with flake8<5. Due to some issues that mean that some users are unable to upgrade to flake8>=5, however, flake8-pyi no longer intends to remove support for running the plugin with flake8<5 before Python 3.7 has reached end-of-life. As such, the FutureWarning is no longer emitted.

22.8.2

New Error Codes

  • Y047: Detect unused TypeAlias declarations.
  • Y049: Detect unused TypedDict definitions.
  • Y050: Prefer typing_extensions.Never for argument annotations over typing.NoReturn.
  • Y051: Detect redundant unions between Literal types and builtin supertypes (e.g. Literal["foo"] | str, or Literal[5] | int).

Other Changes

  • Support mypy_extensions.TypedDict.

22.8.1

  • Add support for flake8 >= 5.0.0.

22.8.0

New Error Codes

  • Y046: Detect unused Protocols.
  • Y048: Function bodies should contain exactly one statement.

Bugfixes

  • Improve error message for the case where a function body contains a docstring and a ... or pass statement.

Other Changes

  • Pin required flake8 version to <5.0.0 (flake8-pyi is not currently compatible with flake8 5.0.0).

22.7.0

New Error Codes

  • Y041: Ban redundant numeric unions (int | float, int | complex, float | complex)
  • Y042: Type alias names should use CamelCase rather than snake_case
  • Y043: Ban type aliases from having names ending with an uppercase "T"
  • Y044: Discourage unnecessary from __future__ import annotations import (Contributed by Torsten Wörtwein)
  • Y045: Ban returning (Async)Iterable from __(a)iter__ methods

Changed Error Codes

  • Y026: Improve error message for check.
  • Y026: Expand check. Since version 22.4.0, this has only emitted an error for assignments to typing.Literal, typing.Union, and PEP 604 unions. It now also emits an error for any subscription on the right-hand side of a simple assignment, as well as for assignments to typing.Any and None.
  • Y034: Slightly expand check to cover the case where a class inheriting from (Async)Iterator returns (Async)Iterable from __(a)iter__. These classes should nearly always return Self from these methods.

Other Changes

  • Support typing_extensions.overload and typing_extensions.NamedTuple.
  • Support Python 3.11.

22.5.1

Changed Error Codes

  • Y020: Relax check slightly, enabling the idiom __all__ += ["foo", "bar"] to be used in a stub file.

22.5.0

New Error Codes

  • Y039: Use str instead of typing.Text for Python 3 stubs
  • Y040: Never explicitly inherit from object in Python 3 stubs

Changed Error Codes

  • Y029: Teach the check to emit errors for __repr__ and __str__ methods that return builtins.str (as opposed to the unqualified str).
  • Y036: Teach the check that builtins.object (as well as the unqualified object) is acceptable as an annotation for an __(a)exit__ method argument.

22.4.1

New Error Codes

  • Y038: Use from collections.abc import Set as AbstractSet instead of from typing import AbstractSet

Changed Error Codes

  • Y027: Expand to prohibit importing any objects from the typing module that are aliases for objects living collections.abc (except for typing.AbstractSet, which is special-cased).

Bugfixes

  • Improve inaccurate error messages for Y036.

22.4.0

New Error Codes

  • Y036: Check for badly defined __exit__ and __aexit__ methods
  • Y037: Use PEP 604 syntax instead of typing.Union and typing.Optional (Contributed by Oleg Höfling)

Changed Error Codes

  • Y035: Expand to cover __match_args__ inside class definitions, as well as __all__ in the global scope.

Bugfixes

  • Improve Y026 check (regarding typing.TypeAlias) to reduce false-positive errors emitted when the plugin encountered variable aliases in a stub file.

22.3.0

Changed Error Codes

  • Add special-casing so that string literals are allowed in the context of __match_args__ assignments inside a class definition.
  • Add special-casing so that arbitrary values can be assigned to a variable in a stub file if the variable is annotated with Final.

Bugfixes

  • Fix bug where incorrect quoted annotations were not detected within if blocks.

22.2.0

New Error Codes

  • Y032: Prefer object to Any for the second argument in __eq__ and __ne__ methods
  • Y033: Always use annotations in stubs, rather than type comments
  • Y034: Detect common errors where return types are hardcoded, but they should use TypeVars instead
  • Y035: __all__ in a stub has the same semantics as at runtime

Bugfixes

  • Fix bugs in several error codes so that e.g. _T = typing.TypeVar("_T") is recognised as a TypeVar definition (previously only _T = TypeVar("_T") was recognised).
  • Fix bug where foo = False at the module level did not trigger a Y015 error.
  • Fix bug where TypeVars were erroneously flagged as unused if they were only used in a typing.Union subscript.
  • Improve unclear error messages for Y022, Y023 and Y027 error codes.

22.1.0

New Error Codes

  • Y016: Duplicate union member
  • Y017: Disallows assignments with multiple targets or non-name targets
  • Y018: Detect unused TypeVars
  • Y019: Detect TypeVars that should be _typeshed.Self, but aren't
  • Y020: Never use quoted annotations in stubs
  • Y021: Docstrings should not be included in stubs
  • Y022: Prefer stdlib classes over typing aliases
  • Y023: Prefer typing over typing_extensions
  • Y024: Prefer typing.NamedTuple to collections.namedtuple
  • Y026: Require using TypeAlias for type aliases
  • Y025: Always alias collections.abc.Set
  • Y027: Python 2-incompatible extension of Y022
  • Y028: Use class-based syntax for NamedTuples
  • Y029: Never define __repr__ or __str__
  • Y030: Use Literal['foo', 'bar'] instead of Literal['foo'] | Literal['bar']
  • Y031: Use class-based syntax for TypedDicts where possible

Removed Error Codes

  • Y092: Top-level attribute must not have a default value

Changed Error Codes

  • Y001: Extend to cover ParamSpec and TypeVarTuple in addition to TypeVar.
  • Y010: Extend to check async functions in addition to normal functions.
  • Y010: Extend to cover what was previously included in Y090 (disallow assignments in __init__ methods) and Y091 (disallow raise statements). The previous checks were disabled by default.
  • Detect usage of non-integer indices in sys.version_info checks.

Other Changes

  • All errors are now enabled by default.
  • attrs is no longer a dependency.
  • ast_decompiler has been added as a dependency on Python 3.8 and 3.7.
  • Support Python 3.10.
  • Discontinue support for Python 3.6.

20.10.0

Other Changes

  • Support Python 3.9.

20.5.0

New Error Codes

  • Y015: Attribute must not have a default value other than ...
  • Y091: Function body must not contain raise
  • Y092: Top-level attribute must not have a default value

Other Changes

  • Support flake8 3.8.0.

19.3.0

Other Changes

  • Update pyflakes dependency.

19.2.0

New Error Codes

  • Y012: Class body must not contain pass
  • Y013: Non-empty class body must not contain ...
  • Y014: Only simple default values are allowed for any function arguments

Other Changes

  • Support Python 3.7.
  • Use --stdin-display-name as the filename when reading from stdin.

18.3.1

New Error Codes

  • Y011: Allow only simple default values

18.3.0

Release herp derp, don't use.

17.3.0

New Error Codes

  • Y001: Y010
  • Y090 (disabled by default)

17.1.0

Other Changes

  • Handle del statements in stub files.

16.12.2

Other Changes

  • Handle annotated assignments in 3.6+ with forward reference support.

16.12.1

Other Changes

  • Handle forward references during subclassing on module level.
  • Handle forward references during type aliasing assignments on module level.

16.12.0

First published version