You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A crash results when mypy --strict is run on the following.
importtypingimportnumpyasnp#This is the type of `np.ma.masked`.MC=np.ma.core.MaskedConstantclassA:
def__init__(self) ->None:
self._error: typing.Union[float, MC, None] =Nonedeferror(self) ->float:
ifself._errorisNone:
passreturn0.0
There is no crash when either of the following changes are made:
I use the full type name instead of the alias in the annotation for self._error.
I remove float and/or None from the union.
mypy complains that MC is an invalid type. I assume that is related. The traceback:
minimal.py:3: error: No library stub file for module 'numpy'
minimal.py:3: note: (Stub files are from https://github.com/python/typeshed)
minimal.py:10: error: Invalid type "minimal.MC"
minimal.py:13: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.560
Traceback (most recent call last):
File "/usr/bin/mypy", line 11, in <module>
load_entry_point('mypy==0.560', 'console_scripts', 'mypy')()
File "/usr/lib/python3/dist-packages/mypy/__main__.py", line 7, in console_entry
main(None)
File "/usr/lib/python3/dist-packages/mypy/main.py", line 66, in main
res = type_check_only(sources, bin_dir, options)
File "/usr/lib/python3/dist-packages/mypy/main.py", line 119, in type_check_only
options=options)
File "/usr/lib/python3/dist-packages/mypy/build.py", line 218, in build
graph = dispatch(sources, manager)
File "/usr/lib/python3/dist-packages/mypy/build.py", line 1997, in dispatch
process_graph(graph, manager)
File "/usr/lib/python3/dist-packages/mypy/build.py", line 2299, in process_graph
process_stale_scc(graph, scc, manager)
File "/usr/lib/python3/dist-packages/mypy/build.py", line 2475, in process_stale_scc
graph[id].type_check_first_pass()
File "/usr/lib/python3/dist-packages/mypy/build.py", line 1876, in type_check_first_pass
self.type_checker().check_first_pass()
File "/usr/lib/python3/dist-packages/mypy/checker.py", line 196, in check_first_pass
self.accept(d)
File "/usr/lib/python3/dist-packages/mypy/checker.py", line 286, in accept
stmt.accept(self)
File "/usr/lib/python3/dist-packages/mypy/nodes.py", line 696, in accept
return visitor.visit_class_def(self)
File "/usr/lib/python3/dist-packages/mypy/checker.py", line 1210, in visit_class_def
self.accept(defn.defs)
File "/usr/lib/python3/dist-packages/mypy/checker.py", line 286, in accept
stmt.accept(self)
File "/usr/lib/python3/dist-packages/mypy/nodes.py", line 756, in accept
return visitor.visit_block(self)
File "/usr/lib/python3/dist-packages/mypy/checker.py", line 1330, in visit_block
self.accept(s)
File "/usr/lib/python3/dist-packages/mypy/checker.py", line 286, in accept
stmt.accept(self)
File "/usr/lib/python3/dist-packages/mypy/nodes.py", line 497, in accept
return visitor.visit_func_def(self)
File "/usr/lib/python3/dist-packages/mypy/checker.py", line 534, in visit_func_def
self.check_func_item(defn, name=defn.name())
File "/usr/lib/python3/dist-packages/mypy/checker.py", line 599, in check_func_item
self.check_func_def(defn, typ, name)
File "/usr/lib/python3/dist-packages/mypy/checker.py", line 762, in check_func_def
self.accept(item.body)
File "/usr/lib/python3/dist-packages/mypy/checker.py", line 286, in accept
stmt.accept(self)
File "/usr/lib/python3/dist-packages/mypy/nodes.py", line 756, in accept
return visitor.visit_block(self)
File "/usr/lib/python3/dist-packages/mypy/checker.py", line 1330, in visit_block
self.accept(s)
File "/usr/lib/python3/dist-packages/mypy/checker.py", line 286, in accept
stmt.accept(self)
File "/usr/lib/python3/dist-packages/mypy/nodes.py", line 921, in accept
return visitor.visit_if_stmt(self)
File "/usr/lib/python3/dist-packages/mypy/checker.py", line 2191, in visit_if_stmt
if_map, else_map = self.find_isinstance_check(e)
File "/usr/lib/python3/dist-packages/mypy/checker.py", line 2812, in find_isinstance_check
return find_isinstance_check(n, self.type_map)
File "/usr/lib/python3/dist-packages/mypy/checker.py", line 3140, in find_isinstance_check
if_vars, else_vars = conditional_type_map(expr, vartype, none_typ)
File "/usr/lib/python3/dist-packages/mypy/checker.py", line 2877, in conditional_type_map
remaining_type = restrict_subtype_away(current_type, proposed_precise_type)
File "/usr/lib/python3/dist-packages/mypy/subtypes.py", line 784, in restrict_subtype_away
new_items = [item for item in t.relevant_items()
File "/usr/lib/python3/dist-packages/mypy/subtypes.py", line 785, in <listcomp>
if (not (is_proper_subtype(erase_type(item), erased_s) or
File "/usr/lib/python3/dist-packages/mypy/erasetype.py", line 25, in erase_type
return typ.accept(EraseTypeVisitor())
File "/usr/lib/python3/dist-packages/mypy/types.py", line 194, in accept
return visitor.visit_unbound_type(self)
File "/usr/lib/python3/dist-packages/mypy/erasetype.py", line 31, in visit_unbound_type
assert False, 'Not supported'
AssertionError: Not supported
minimal.py:13: : note: use --pdb to drop into pdb
There are no numpy stubs, so that's presumably why MC is deemed invalid. The crash itself is probably due to #4543, but I'm not sure whether to call it a duplicate (since that issue has a forward reference, not an invalid type).
A crash results when
mypy --strict
is run on the following.There is no crash when either of the following changes are made:
self._error
.float
and/orNone
from the union.mypy complains that
MC
is an invalid type. I assume that is related. The traceback:Version numbers:
The text was updated successfully, but these errors were encountered: