You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$ mypy --enable-recursive-aliases nested.pySuccess: no issues found in 1 source file
Run pylint:
$ pylint nested.py ************* Module nestednested.py:7:27: E0601: Using variable 'Nested' before assignment (used-before-assignment)------------------------------------------------------------------Your code has been rated at 0.00/10 (previous run: 0.00/10, +0.00)
$ python3 nested.pyTraceback (most recent call last): File "nested.py", line 7, in <module> Nested = Sequence[Union[T, Nested[T]]]NameError: name 'Nested' is not defined
$ mypy --enable-recursive-aliases nested_forwardref.pySuccess: no issues found in 1 source file
$ pylint nested_forwardref.py------------------------------------Your code has been rated at 10.00/10
$ python3 python3 nested_forwardref.pytyping.Sequence[typing.Union[int, ForwardRef('Nested[T]')]]
Expected Behavior
Raise errors for generic recursive types.
or
support generic ForwardRef (preferred, but maybe need support by Python)
Actual Behavior
No error raise when using the variable name without a ForwardRef.
Bug Report
In:
We now support recursive type hints, such as:
But in the example in #13297 (comment), which is generic and has typevars:
The code is Python syntax illegal that the name
Nested
inNested[T]
is referenced before assignment.My own use case: define a generic pytree type:
I got
NameError
is usePyTree[T]
. Or the typevarT
is not expended when usingForwardRef
('PyTree[T]'
):To Reproduce
mypy
does not reportNameError
for recursive type:pylint
and the dev version ofmypy
:mypy
:pylint
:ForwardRef
does not expand typevars:ForwardRef
:mypy
,pylint
and execute:Expected Behavior
or
ForwardRef
(preferred, but maybe need support by Python)Actual Behavior
No error raise when using the variable name without a
ForwardRef
.Ref:
typing.ForwardRef
to support generic recursive types.Your Environment
--enable-recursive-aliases
mypy.ini
(and other config files): NoneThe text was updated successfully, but these errors were encountered: