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

unpacking assignment with self annotated as typing.Self in typing.NamedTuple subclass method causes mypy internal error #17010

Closed
Floozutter opened this issue Mar 10, 2024 · 1 comment · Fixed by #17351

Comments

@Floozutter
Copy link

Crash Report
Inside of typing.NamedTuple subclass methods, unpacking assignments with self annotated as typing.Self on the right-hand side causes mypy to fail (internal error).

Traceback

$ mypy --show-traceback foo.py
foo.py:6: 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: 1.9.0
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "mypy\checker.py", line 595, in accept
  File "mypy\nodes.py", line 1310, in accept
  File "mypy\checker.py", line 2823, in visit_assignment_stmt
  File "mypy\checker.py", line 2878, in check_assignment
  File "mypy\checker.py", line 3580, in check_assignment_to_multiple_lvalues
  File "mypy\checker.py", line 3658, in check_multi_assignment
  File "mypy\checker.py", line 3797, in check_multi_assignment_from_tuple
AssertionError:
foo.py:6: : note: use --pdb to drop into pdb

To Reproduce

import typing

class Foo(typing.NamedTuple):
    bar: int
    def baz(self: typing.Self) -> None:
        _ ,= self

mypy-play gist
mypy-play playground

Alternate example showing that this can occur even when self is not directly annotated as typing.Self:
alternate example mypy-play gist
alternate example mypy-play playground

Your Environment

  • Mypy version used: 1.9.0
  • Mypy command-line flags: --show-traceback
  • Mypy configuration options from mypy.ini (and other config files):
  • Python version used: 3.12.2
  • Operating system and version: Microsoft Windows 11 Home
@Floozutter
Copy link
Author

Previously, I opened issue #17009 with the wrong label "bug". I closed that issue and opened this with the correct label "crash".

ilevkivskyi added a commit that referenced this issue Jun 9, 2024
Fixes #17010

Fix is trivial: replicate the `TypeVar` handling logic in the caller.
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.

2 participants