Closed
Description
Crash Report
MyPy crashes when run against a Generic dataclass using a TypeVar with an ill-defined bound which is passed in quotes.
Traceback
crash.py:7: error: Name "NotDefined" is not defined
crash.py:11: error: INTERNAL ERROR -- Please try using mypy master on Github:
https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build
Please report a bug at https://github.com/python/mypy/issues
version: 0.942
Traceback (most recent call last):
File "C:\Users\<user>\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Users\<user>\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "mypy\semanal.py", line 5220, in accept
File "mypy\nodes.py", line 739, in accept
File "mypy\semanal.py", line 630, in visit_func_def
File "mypy\semanal.py", line 662, in analyze_func_def
File "mypy\semanal.py", line 4920, in defer
AssertionError: Must not defer during final iteration
crash.py:11: : note: use --pdb to drop into pdb
To Reproduce
Run mypy against the following Python module (crash.py
):
import dataclasses
from typing import Generic, TypeVar
T = TypeVar("T", bound="NotDefined")
@dataclasses.dataclass
class C(Generic[T]):
x: float
N.B.:
The crash does not happen (and mypy reports crash.py:4: error: Name "NotDefined" is not defined
as expected) if:
NotDefined
is passed without quotes- The line
x: float
is replaced with...
T
is not defined at all
Your Environment
- Mypy version used: 0.942
- Mypy command-line flags: none
- Python version used: 3.8.6
- Operating system and version: Windows 10 Pro
- Mypy configuration options from
mypy.ini
(and other config files):
[mypy]
python_version = 3.8
warn_return_any = True
warn_unused_configs = True
mypy_path = <path to mypy>
show_error_codes = True
ignore_missing_imports = False
follow_imports = silent