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

Unexpected behavior on using NamedTuple and Generic when bounding TypeVar in different ways #10672

Closed
yoyoLeeTW opened this issue Jun 19, 2021 · 2 comments

Comments

@yoyoLeeTW
Copy link

Crash Report / Traceback / To Reproduce

I try to use NamedTuple and Generic such as the following code:

# test.py
from typing import (NamedTuple, Generic, TypeVar)

S = TypeVar('S', bound='_S')

class _S:
    pass

class A(NamedTuple, Generic[S]):
    s: S

In this case mypy raises an internal error:

test.py:9: 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.902
Traceback (most recent call last):
  File "mypy/semanal.py", line 4872, in accept
  File "mypy/nodes.py", line 687, in accept
  File "mypy/semanal.py", line 577, in visit_func_def
  File "mypy/semanal.py", line 609, in analyze_func_def
  File "mypy/semanal.py", line 4583, in defer
AssertionError: Must not defer during final iteration
test.py:9: : note: use --pdb to drop into pdb

But mypy returns "sucess" with code 0 if I swap class _S and S:

# test.py
from typing import (NamedTuple, Generic, TypeVar)

class _S:
    pass

S = TypeVar('S', bound='_S')

class A(NamedTuple, Generic[S]):
    s: S

Your Environment

  • Mypy version used: 0.902
  • Mypy command-line flags: mypy --show-traceback test.py
  • Mypy configuration options from mypy.ini (and other config files): None
  • Python version used: 3.8.0
  • Operating system and version: Ubuntu 18.04.5
@AlexWaygood
Copy link
Member

AlexWaygood commented Mar 26, 2022

Same assertion is hit in #12113, #10140, #11728, #12252, #10672 and #12112

@ilevkivskyi
Copy link
Member

Both examples now pass on master without errors

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

No branches or pull requests

3 participants