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

Internal error using compile re in inner function #9034

Closed
RonVider opened this issue Jun 23, 2020 · 3 comments
Closed

Internal error using compile re in inner function #9034

RonVider opened this issue Jun 23, 2020 · 3 comments
Labels

Comments

@RonVider
Copy link

Running mypy on latest master raises internal error for the following code:

import re


def func(arg: str) -> None:
    if not (match := re_pattern.match(arg)):
        return

    print(arg)


re_pattern = re.compile(r".*")

func("hello")

Traceback attached:

/tmp/tst.py:5: 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.781
Traceback (most recent call last):
  File "/usr/local/bin/mypy", line 8, in <module>
    sys.exit(console_entry())
  File "/usr/local/lib/python3.8/site-packages/mypy/__main__.py", line 8, in console_entry
    main(None, sys.stdout, sys.stderr)
  File "/usr/local/lib/python3.8/site-packages/mypy/main.py", line 89, in main
    res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
  File "/usr/local/lib/python3.8/site-packages/mypy/build.py", line 180, in build
    result = _build(
  File "/usr/local/lib/python3.8/site-packages/mypy/build.py", line 252, in _build
    graph = dispatch(sources, manager, stdout)
  File "/usr/local/lib/python3.8/site-packages/mypy/build.py", line 2626, in dispatch
    process_graph(graph, manager)
  File "/usr/local/lib/python3.8/site-packages/mypy/build.py", line 2949, in process_graph
    process_stale_scc(graph, scc, manager)
  File "/usr/local/lib/python3.8/site-packages/mypy/build.py", line 3047, in process_stale_scc
    graph[id].type_check_first_pass()
  File "/usr/local/lib/python3.8/site-packages/mypy/build.py", line 2107, in type_check_first_pass
    self.type_checker().check_first_pass()
  File "/usr/local/lib/python3.8/site-packages/mypy/checker.py", line 294, in check_first_pass
    self.accept(d)
  File "/usr/local/lib/python3.8/site-packages/mypy/checker.py", line 401, in accept
    stmt.accept(self)
  File "/usr/local/lib/python3.8/site-packages/mypy/nodes.py", line 676, in accept
    return visitor.visit_func_def(self)
  File "/usr/local/lib/python3.8/site-packages/mypy/checker.py", line 726, in visit_func_def
    self._visit_func_def(defn)
  File "/usr/local/lib/python3.8/site-packages/mypy/checker.py", line 730, in _visit_func_def
    self.check_func_item(defn, name=defn.name)
  File "/usr/local/lib/python3.8/site-packages/mypy/checker.py", line 792, in check_func_item
    self.check_func_def(defn, typ, name)
  File "/usr/local/lib/python3.8/site-packages/mypy/checker.py", line 975, in check_func_def
    self.accept(item.body)
  File "/usr/local/lib/python3.8/site-packages/mypy/checker.py", line 401, in accept
    stmt.accept(self)
  File "/usr/local/lib/python3.8/site-packages/mypy/nodes.py", line 1004, in accept
    return visitor.visit_block(self)
  File "/usr/local/lib/python3.8/site-packages/mypy/checker.py", line 1973, in visit_block
    self.accept(s)
  File "/usr/local/lib/python3.8/site-packages/mypy/checker.py", line 401, in accept
    stmt.accept(self)
  File "/usr/local/lib/python3.8/site-packages/mypy/nodes.py", line 1195, in accept
    return visitor.visit_if_stmt(self)
  File "/usr/local/lib/python3.8/site-packages/mypy/checker.py", line 3212, in visit_if_stmt
    if_map, else_map = self.find_isinstance_check(e)
  File "/usr/local/lib/python3.8/site-packages/mypy/checker.py", line 3928, in find_isinstance_check
    if_map, else_map = self.find_isinstance_check_helper(node)
  File "/usr/local/lib/python3.8/site-packages/mypy/checker.py", line 4135, in find_isinstance_check_helper
    left, right = self.find_isinstance_check_helper(node.expr)
  File "/usr/local/lib/python3.8/site-packages/mypy/checker.py", line 4104, in find_isinstance_check_helper
    return self.find_isinstance_check_helper(node.target)
  File "/usr/local/lib/python3.8/site-packages/mypy/checker.py", line 4108, in find_isinstance_check_helper
    vartype = type_map[node]
KeyError: <mypy.nodes.NameExpr object at 0x7f832bd6c0c0>
@ilevkivskyi
Copy link
Member

Confirm the crash. Note there is also #8986

@hauntsaninja
Copy link
Collaborator

hauntsaninja commented Sep 25, 2020

Closing as a dupe of #9054 which now has a little more discussion

@hauntsaninja
Copy link
Collaborator

@RonVider thanks for reporting! And thanks to llchan this should be fixed on master :-) I was wondering if the code you're working on is open source? My interest is in adding projects to https://github.com/hauntsaninja/mypy_primer that use newer Python features.

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

No branches or pull requests

3 participants