Releases: PyCQA/flake8-pyi
23.6.0
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 returningtyping_extensions.Self
- Introduce Y057: Do not use
typing.ByteString
orcollections.abc.ByteString
. These types have unclear semantics, and are deprecated; usetyping_extensions.Buffer
or a union such asbytes | 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 thatx: int
in a stub file is sufficient forx
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: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
23.4.0
Update error messages for Y019 and Y034 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.
Other changes:
- Y011/Y014/Y015: Simple container literals (
list
,dict
,tuple
andset
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
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
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__
.
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 assys.maxsize
. - Disallow
str
orbytes
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 assys.maxsize
andsys.executable
. - Fewer Y020 false positives are now emitted when encountering default values in stub files.
23.1.0
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
andtyping.Pattern
have been added to the list of imports banned by Y022. Usere.Match
andre.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
,bool
s,int
s,float
s,complex
numbers, strings andbytes
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
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
orcomplex | int
)
in all contexts outside of type aliases. This was incorrect. PEP 484 only
specifies that type checkers should treatint
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.