-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Description
I was trying to implicitly convert the types of some attributes when assigned to following the approach in #6940. However I met an internal error when an incompatible assignment occurs.
My current repro:
# container.pyi
_T = TypeVar('_T')
class DataTypeA: ...
class DataTypeB: ...
class CoerciveContainer( Protocol, Generic[_T] ):
@overload
def __set__( s, obj, value: Container[_T] ) -> None: ...
@overload
def __set__( s, obj, value: _T ) -> None: ...
class Container( CoerciveContainer[_T], Generic[_T] ): ...
# bar.py
from container import *
class Bar:
def __init__( s ) -> None:
s.foo = Container[DataTypeA]()
s.foo = DataTypeB() # crash at this line
failed with
(mypy) $ mypy bar.py --show-traceback
bar.py:6: 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.720+dev.dc6da54f50d5443fe46308046719043eba03c84d
Traceback (most recent call last):
File "///.virtualenvs/mypy/bin/mypy", line 10, in <module>
sys.exit(console_entry())
File "///.virtualenvs/mypy/lib/python3.7/site-packages/mypy/__main__.py", line 8, in console_entry
main(None, sys.stdout, sys.stderr)
File "///.virtualenvs/mypy/lib/python3.7/site-packages/mypy/main.py", line 83, in main
res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
File "///.virtualenvs/mypy/lib/python3.7/site-packages/mypy/build.py", line 164, in build
result = _build(sources, options, alt_lib_path, flush_errors, fscache, stdout, stderr)
File "///.virtualenvs/mypy/lib/python3.7/site-packages/mypy/build.py", line 224, in _build
graph = dispatch(sources, manager, stdout)
File "///.virtualenvs/mypy/lib/python3.7/site-packages/mypy/build.py", line 2579, in dispatch
process_graph(graph, manager)
File "///.virtualenvs/mypy/lib/python3.7/site-packages/mypy/build.py", line 2892, in process_graph
process_stale_scc(graph, scc, manager)
File "///.virtualenvs/mypy/lib/python3.7/site-packages/mypy/build.py", line 2999, in process_stale_scc
graph[id].type_check_first_pass()
File "///.virtualenvs/mypy/lib/python3.7/site-packages/mypy/build.py", line 2108, in type_check_first_pass
self.type_checker().check_first_pass()
File "///.virtualenvs/mypy/lib/python3.7/site-packages/mypy/checker.py", line 285, in check_first_pass
self.accept(d)
File "///.virtualenvs/mypy/lib/python3.7/site-packages/mypy/checker.py", line 396, in accept
stmt.accept(self)
File "///.virtualenvs/mypy/lib/python3.7/site-packages/mypy/nodes.py", line 922, in accept
return visitor.visit_class_def(self)
File "///.virtualenvs/mypy/lib/python3.7/site-packages/mypy/checker.py", line 1634, in visit_class_def
self.accept(defn.defs)
File "///.virtualenvs/mypy/lib/python3.7/site-packages/mypy/checker.py", line 396, in accept
stmt.accept(self)
File "///.virtualenvs/mypy/lib/python3.7/site-packages/mypy/nodes.py", line 987, in accept
return visitor.visit_block(self)
File "///.virtualenvs/mypy/lib/python3.7/site-packages/mypy/checker.py", line 1830, in visit_block
self.accept(s)
File "///.virtualenvs/mypy/lib/python3.7/site-packages/mypy/checker.py", line 396, in accept
stmt.accept(self)
File "///.virtualenvs/mypy/lib/python3.7/site-packages/mypy/nodes.py", line 663, in accept
return visitor.visit_func_def(self)
File "///.virtualenvs/mypy/lib/python3.7/site-packages/mypy/checker.py", line 707, in visit_func_def
self._visit_func_def(defn)
File "///.virtualenvs/mypy/lib/python3.7/site-packages/mypy/checker.py", line 711, in _visit_func_def
self.check_func_item(defn, name=defn.name())
File "///.virtualenvs/mypy/lib/python3.7/site-packages/mypy/checker.py", line 773, in check_func_item
self.check_func_def(defn, typ, name)
File "///.virtualenvs/mypy/lib/python3.7/site-packages/mypy/checker.py", line 952, in check_func_def
self.accept(item.body)
File "///.virtualenvs/mypy/lib/python3.7/site-packages/mypy/checker.py", line 396, in accept
stmt.accept(self)
File "///.virtualenvs/mypy/lib/python3.7/site-packages/mypy/nodes.py", line 987, in accept
return visitor.visit_block(self)
File "///.virtualenvs/mypy/lib/python3.7/site-packages/mypy/checker.py", line 1830, in visit_block
self.accept(s)
File "///.virtualenvs/mypy/lib/python3.7/site-packages/mypy/checker.py", line 396, in accept
stmt.accept(self)
File "///.virtualenvs/mypy/lib/python3.7/site-packages/mypy/nodes.py", line 1045, in accept
return visitor.visit_assignment_stmt(self)
File "///.virtualenvs/mypy/lib/python3.7/site-packages/mypy/checker.py", line 1864, in visit_assignment_stmt
self.check_assignment(s.lvalues[-1], s.rvalue, s.type is None, s.new_syntax)
File "///.virtualenvs/mypy/lib/python3.7/site-packages/mypy/checker.py", line 1970, in check_assignment
instance_type, lvalue_type, rvalue, lvalue)
File "///.virtualenvs/mypy/lib/python3.7/site-packages/mypy/checker.py", line 2748, in check_member_assignment
assert isinstance(inferred_dunder_set_type, CallableType)
AssertionError:
bar.py:6: : note: use --pdb to drop into pdb
I'm using the master branch mypy.