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 fails to check recursive/cyclic type aliases, even with #731 being part of v0.991. However, this happens on Python 3.8 and 3.9 only (and possibly below), but not on 3.10 or 3.11.
Example:
Expected Behavior
Mypy not raising any errors for recursive/cyclig type aliases and correctly parsing them as it does on Python 3.10 and 3.11.
Actual Behavior
Mypy fails on recursive/cyclic type aliases with the error error: Cannot resolve name "RecursiveTypeAlias" (possible cyclic definition) [misc].
Note the awkward import fallback is needed because doing it the opposite does not work py39 or py38 either, only importing first from typing_extensions seems to be working well.
Reacted by Fritz Obermeyer, Nick Sweeting and Sam Martin-Brown
Activity
JukkaL commentedon Nov 29, 2022
On a recent master this works on Python 3.8:
The issue is with imports. Mypy doesn't support this on Python 3.8:
As a workaround, this should work:
bartfeenstra commentedon Nov 29, 2022
I can confirm this works with mypy commit
3a3cf412b278ee7bf710742b168beed41c1c02f2in combination with the imports turned around. Thanks!ssbarnea commentedon Apr 30, 2023
For reference, this is the full solution that seems to currently work with py39+ and also pass mypy and ruff:
Note the awkward import fallback is needed because doing it the opposite does not work py39 or py38 either, only importing first from typing_extensions seems to be working well.