Skip to content

mypy crash when variable defined after the function #9184

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

Closed
yoav-orca opened this issue Jul 21, 2020 · 1 comment
Closed

mypy crash when variable defined after the function #9184

yoav-orca opened this issue Jul 21, 2020 · 1 comment

Comments

@yoav-orca
Copy link

Note: if you are reporting a wrong signature of a function or a class in
the standard library, then the typeshed tracker is better suited
for this report: https://github.com/python/typeshed/issues

Please provide more information to help us understand the issue:

  • Are you reporting a bug, or opening a feature request?
    A bug
  • Please insert below the code you are checking with mypy,
    or a mock-up repro if the source is private. We would appreciate
    if you try to simplify your case to a minimal repro.
import re

def match(s: str) -> None:
    if m := rx.match(s):
        print(m)

rx = re.compile("X")
  • What is the actual behavior/output?
mypy --strict "scratch_4.py" --show-traceback
scratch_4.py:4: error: INTERNAL ERROR -- Please try using mypy master on Github:
https://mypy.rtfd.io/en/latest/common_issues.html#using-a-development-mypy-build
Please report a bug at https://github.com/python/mypy/issues
version: 0.782
Traceback (most recent call last):
  File "mypy/checker.py", line 401, in accept
  File "mypy/nodes.py", line 1195, in accept
  File "mypy/checker.py", line 3212, in visit_if_stmt
  File "mypy/checker.py", line 3928, in find_isinstance_check
  File "mypy/checker.py", line 4104, in find_isinstance_check_helper
  File "mypy/checker.py", line 4108, in find_isinstance_check_helper
KeyError: <mypy.nodes.NameExpr object at 0x110664120>
scratch_4.py:4: : note: use --pdb to drop into pdb
  • What is the behavior/output you expect?
    To type check successfully

  • What are the versions of mypy and Python you are using?
    Do you see the same issue after installing mypy from Git master?
    I'm using CPython 3.8.4 & mypy 0.782, it reproduces with mypy 0.790+dev.a5455bd9f37825d24415e46a4d278d71502c9d07

  • What are the mypy flags you are using? (For example --strict-optional)
    --strict

  • If mypy crashed with a traceback, please paste
    the full traceback below.

Traceback (most recent call last):
  File "mypy/checker.py", line 401, in accept
  File "mypy/nodes.py", line 1195, in accept
  File "mypy/checker.py", line 3212, in visit_if_stmt
  File "mypy/checker.py", line 3928, in find_isinstance_check
  File "mypy/checker.py", line 4104, in find_isinstance_check_helper
  File "mypy/checker.py", line 4108, in find_isinstance_check_helper
KeyError: <mypy.nodes.NameExpr object at 0x110664120>

(You can freely edit this text, please remove all the lines
you believe are unnecessary.)

@ilevkivskyi
Copy link
Member

I think this is a duplicate of #9054

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

No branches or pull requests

2 participants