Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash when TypeVar of Generic dataclass has undefined bound #12527

Closed
jamiesandenr opened this issue Apr 5, 2022 · 4 comments · Fixed by #12791
Closed

Crash when TypeVar of Generic dataclass has undefined bound #12527

jamiesandenr opened this issue Apr 5, 2022 · 4 comments · Fixed by #12791

Comments

@jamiesandenr
Copy link

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
@AlexWaygood
Copy link
Member

AlexWaygood commented Apr 5, 2022

Looks like it's dataclasses-specific. I can reproduce with dataclasses, but not without.

@AlexWaygood
Copy link
Member

Looks like this crash was fixed in #12762. @JukkaL, do you think we should add another test case, or just close this out?

@AlexWaygood
Copy link
Member

Looks like this crash was fixed in #12762. @JukkaL, do you think we should add another test case, or just close this out?

Cc. @JelleZijlstra as well :)

@JelleZijlstra
Copy link
Member

I always like more test cases when we fix something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants