Repository navigation
Internal Error when overriding a generic variable in __init__ #5846
Copy link
Copy link
Closed
Labels
Description
This is a bug report.
I created a simple python file called breakmypy.py which has the following contents:
# contents of breakmypy.py
from collections import UserDict
class MyDict(UserDict):
def __init__(self):
self.data: dict = {}When I run mypy breakmypy.py --show-traceback the following output is emitted:
breakmypy.py:14: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.630
Traceback (most recent call last):
File "/home/derrick_chambers/anaconda3/bin/mypy", line 11, in <module>
sys.exit(console_entry())
File "/home/derrick_chambers/anaconda3/lib/python3.7/site-packages/mypy/__main__.py", line 7, in console_entry
main(None)
File "/home/derrick_chambers/anaconda3/lib/python3.7/site-packages/mypy/main.py", line 91, in main
res = type_check_only(sources, bin_dir, options, flush_errors, fscache) # noqa
File "/home/derrick_chambers/anaconda3/lib/python3.7/site-packages/mypy/main.py", line 148, in type_check_only
fscache=fscache)
File "/home/derrick_chambers/anaconda3/lib/python3.7/site-packages/mypy/build.py", line 183, in build
flush_errors, fscache)
File "/home/derrick_chambers/anaconda3/lib/python3.7/site-packages/mypy/build.py", line 356, in _build
graph = dispatch(sources, manager)
File "/home/derrick_chambers/anaconda3/lib/python3.7/site-packages/mypy/build.py", line 2543, in dispatch
process_graph(graph, manager)
File "/home/derrick_chambers/anaconda3/lib/python3.7/site-packages/mypy/build.py", line 2840, in process_graph
process_stale_scc(graph, scc, manager)
File "/home/derrick_chambers/anaconda3/lib/python3.7/site-packages/mypy/build.py", line 2963, in process_stale_scc
graph[id].type_check_first_pass()
File "/home/derrick_chambers/anaconda3/lib/python3.7/site-packages/mypy/build.py", line 2103, in type_check_first_pass
self.type_checker().check_first_pass()
File "/home/derrick_chambers/anaconda3/lib/python3.7/site-packages/mypy/checker.py", line 256, in check_first_pass
self.accept(d)
File "/home/derrick_chambers/anaconda3/lib/python3.7/site-packages/mypy/checker.py", line 355, in accept
stmt.accept(self)
File "/home/derrick_chambers/anaconda3/lib/python3.7/site-packages/mypy/nodes.py", line 820, in accept
return visitor.visit_class_def(self)
File "/home/derrick_chambers/anaconda3/lib/python3.7/site-packages/mypy/checker.py", line 1461, in visit_class_def
self.accept(defn.defs)
File "/home/derrick_chambers/anaconda3/lib/python3.7/site-packages/mypy/checker.py", line 355, in accept
stmt.accept(self)
File "/home/derrick_chambers/anaconda3/lib/python3.7/site-packages/mypy/nodes.py", line 885, in accept
return visitor.visit_block(self)
File "/home/derrick_chambers/anaconda3/lib/python3.7/site-packages/mypy/checker.py", line 1607, in visit_block
self.accept(s)
File "/home/derrick_chambers/anaconda3/lib/python3.7/site-packages/mypy/checker.py", line 355, in accept
stmt.accept(self)
File "/home/derrick_chambers/anaconda3/lib/python3.7/site-packages/mypy/nodes.py", line 603, in accept
return visitor.visit_func_def(self)
File "/home/derrick_chambers/anaconda3/lib/python3.7/site-packages/mypy/checker.py", line 666, in visit_func_def
self._visit_func_def(defn)
File "/home/derrick_chambers/anaconda3/lib/python3.7/site-packages/mypy/checker.py", line 670, in _visit_func_def
self.check_func_item(defn, name=defn.name())
File "/home/derrick_chambers/anaconda3/lib/python3.7/site-packages/mypy/checker.py", line 732, in check_func_item
self.check_func_def(defn, typ, name)
File "/home/derrick_chambers/anaconda3/lib/python3.7/site-packages/mypy/checker.py", line 898, in check_func_def
self.accept(item.body)
File "/home/derrick_chambers/anaconda3/lib/python3.7/site-packages/mypy/checker.py", line 355, in accept
stmt.accept(self)
File "/home/derrick_chambers/anaconda3/lib/python3.7/site-packages/mypy/nodes.py", line 885, in accept
return visitor.visit_block(self)
File "/home/derrick_chambers/anaconda3/lib/python3.7/site-packages/mypy/checker.py", line 1607, in visit_block
self.accept(s)
File "/home/derrick_chambers/anaconda3/lib/python3.7/site-packages/mypy/checker.py", line 355, in accept
stmt.accept(self)
File "/home/derrick_chambers/anaconda3/lib/python3.7/site-packages/mypy/nodes.py", line 933, in accept
return visitor.visit_assignment_stmt(self)
File "/home/derrick_chambers/anaconda3/lib/python3.7/site-packages/mypy/checker.py", line 1614, in visit_assignment_stmt
self.check_assignment(s.lvalues[-1], s.rvalue, s.type is None, s.new_syntax)
File "/home/derrick_chambers/anaconda3/lib/python3.7/site-packages/mypy/checker.py", line 1663, in check_assignment
if self.check_compatibility_all_supers(lvalue, lvalue_type, rvalue):
File "/home/derrick_chambers/anaconda3/lib/python3.7/site-packages/mypy/checker.py", line 1755, in check_compatibility_all_supers
base_type, base_node = self.lvalue_type_from_base(lvalue_node, base)
File "/home/derrick_chambers/anaconda3/lib/python3.7/site-packages/mypy/checker.py", line 1842, in lvalue_type_from_base
assert self_type is not None, "Internal error: base lookup outside class"
AssertionError: Internal error: base lookup outside class
breakmypy.py:14: : note: use --pdb to drop into pdbReactions are currently unavailable
Activity
ilevkivskyi commentedon Oct 27, 2018
This still crashes on master, here is a bit more self-contained repro:
It actually crashes in several similar scenarios, the only requirement is that the variable type in a base class is generic, and it is overridden in a method, I wonder how no one found this before.
This happens in the part of code that I never understood, there is a method called
active_self_type(), but it always returnsNoneat method scope.[-]Internal Failure using UserDict subclass[/-][+]Internal Error when overriding a generic variable in __ini__[/+][-]Internal Error when overriding a generic variable in __ini__[/-][+]Internal Error when overriding a generic variable in __init__[/+]ilevkivskyi commentedon Dec 8, 2018
This crash appeared again in #6033
Levitanus commentedon Jan 19, 2019
in addition
input_python_file.txt
traceback.txt
wiml commentedon Feb 20, 2019
I just hit this crash in version
0.670(and0.660); my minimized case is very similar to the one in ilevkivskyi's comment.mthuurne commentedon Apr 26, 2019
I hit this error in mypy 0.701, also with a method that overrides the type of a base class member that was generic in the base class.
mthuurne commentedon Apr 26, 2019
I found a workaround:
Fix the logic in active self-type calculation for current scope (#7235)