Skip to content

Releases: PyCQA/flake8-pyi

23.5.0

01 May 21:53
80d3cba
Compare
Choose a tag to compare
  • 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.

  • 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

13 Apr 10:08
95d65fe
Compare
Choose a tag to compare
  • Introduce 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

10 Apr 12:29
f02c98d
Compare
Choose a tag to compare

Update error messages for Y019 and Y034 to recommend using typing_extensions.Self rather than _typeshed.Self.

23.3.1

20 Mar 16:49
7289823
Compare
Choose a tag to compare

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.

Other changes:

  • Y011/Y014/Y015: Simple container literals (list, dict, tuple and set literals) are now allowed as default values.
  • Y052 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

14 Mar 20:52
69df360
Compare
Choose a tag to compare

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

31 Jan 23:50
78c9d26
Compare
Choose a tag to compare
  • 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

28 Jan 14:49
6b18eec
Compare
Choose a tag to compare

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

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.
  • Fewer Y020 false positives are now emitted when encountering default values in stub files.

23.1.0

16 Jan 18:27
503d2df
Compare
Choose a tag to compare

Bugfixes:

  • Do not emit Y020 (quoted annotations) for strings in parameter defaults.
  • Fix checking of defaults for functions with positional-only parameters.

Other changes:

  • Modify Y036 so that _typeshed.Unused is allowed as an annotation for parameters in __(a)exit__ methods. Contributed by Avasam
  • Several changes have been made to error codes relating to imports:
    • The Y027 error code has been removed.
    • All errors that used to result in Y027 being emitted now result in Y022 being emitted instead.
    • Some errors that used to result in Y023 being emitted now result in Y022 being emitted instead.
    • typing.Match and typing.Pattern have been added to the list of imports banned by Y022. Use re.Match and re.Pattern instead.
  • 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.
  • Y011, Y014 and Y015 have all been significantly relaxed. None, bools, ints, floats, complex numbers, strings and bytes are all now allowed as default values for parameter annotations or assignments.
  • Hatchling is now used as the build backend. This should have minimal, if any, user-facing impact.

22.11.0

24 Nov 10:56
5693d0a
Compare
Choose a tag to compare

Bugfixes:

  • Specify encoding when opening files. Prevents UnicodeDecodeError on Windows
    when the file contains non-CP1252 characters.
    Contributed by Avasam.
  • Significant changes have been made to the Y041 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.

Other changes:

  • Support running with flake8 v6.

22.10.0

06 Oct 23:31
ec0bb4b
Compare
Choose a tag to compare

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.