Closed
Description
Sample code:
# a.py
def meth(self, x: int) -> int:
return 2 * x
# b.py
class Foo:
from a import meth
foo = Foo()
print(foo.meth(10))
Using latest mypy master (last release also crashes, though with a different traceback):
~/src/mypy$ mypy /tmp/b.py --show-traceback
/tmp/b.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.720+dev.95ac93fdec0f0ae5a9b9ebe2519f7c8eaf1feeb1
Traceback (most recent call last):
File "/home/njs/.user-python3.7/bin/mypy", line 10, in <module>
sys.exit(console_entry())
File "/home/njs/.user-python3.7/lib/python3.7/site-packages/mypy/__main__.py", line 8, in console_entry
main(None, sys.stdout, sys.stderr)
File "/home/njs/.user-python3.7/lib/python3.7/site-packages/mypy/main.py", line 83, in main
res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
File "/home/njs/.user-python3.7/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 "/home/njs/.user-python3.7/lib/python3.7/site-packages/mypy/build.py", line 224, in _build
graph = dispatch(sources, manager, stdout)
File "/home/njs/.user-python3.7/lib/python3.7/site-packages/mypy/build.py", line 2567, in dispatch
process_graph(graph, manager)
File "/home/njs/.user-python3.7/lib/python3.7/site-packages/mypy/build.py", line 2880, in process_graph
process_stale_scc(graph, scc, manager)
File "/home/njs/.user-python3.7/lib/python3.7/site-packages/mypy/build.py", line 2987, in process_stale_scc
graph[id].type_check_first_pass()
File "/home/njs/.user-python3.7/lib/python3.7/site-packages/mypy/build.py", line 2096, in type_check_first_pass
self.type_checker().check_first_pass()
File "/home/njs/.user-python3.7/lib/python3.7/site-packages/mypy/checker.py", line 281, in check_first_pass
self.accept(d)
File "/home/njs/.user-python3.7/lib/python3.7/site-packages/mypy/checker.py", line 392, in accept
stmt.accept(self)
File "/home/njs/.user-python3.7/lib/python3.7/site-packages/mypy/nodes.py", line 993, in accept
return visitor.visit_expression_stmt(self)
File "/home/njs/.user-python3.7/lib/python3.7/site-packages/mypy/checker.py", line 2739, in visit_expression_stmt
self.expr_checker.accept(s.expr, allow_none_return=True, always_allow_any=True)
File "/home/njs/.user-python3.7/lib/python3.7/site-packages/mypy/checkexpr.py", line 3255, in accept
typ = self.visit_call_expr(node, allow_none_return=True)
File "/home/njs/.user-python3.7/lib/python3.7/site-packages/mypy/checkexpr.py", line 234, in visit_call_expr
return self.visit_call_expr_inner(e, allow_none_return=allow_none_return)
File "/home/njs/.user-python3.7/lib/python3.7/site-packages/mypy/checkexpr.py", line 304, in visit_call_expr_inner
ret_type = self.check_call_expr_with_callee_type(callee_type, e, fullname, object_type)
File "/home/njs/.user-python3.7/lib/python3.7/site-packages/mypy/checkexpr.py", line 648, in check_call_expr_with_callee_type
object_type=object_type)[0]
File "/home/njs/.user-python3.7/lib/python3.7/site-packages/mypy/checkexpr.py", line 685, in check_call
object_type)
File "/home/njs/.user-python3.7/lib/python3.7/site-packages/mypy/checkexpr.py", line 770, in check_callable_call
callee, args, arg_kinds, formal_to_actual)
File "/home/njs/.user-python3.7/lib/python3.7/site-packages/mypy/checkexpr.py", line 864, in infer_arg_types_in_context
res[ai] = self.accept(args[ai], callee.arg_types[i])
File "/home/njs/.user-python3.7/lib/python3.7/site-packages/mypy/checkexpr.py", line 3259, in accept
typ = node.accept(self)
File "/home/njs/.user-python3.7/lib/python3.7/site-packages/mypy/nodes.py", line 1518, in accept
return visitor.visit_call_expr(self)
File "/home/njs/.user-python3.7/lib/python3.7/site-packages/mypy/checkexpr.py", line 234, in visit_call_expr
return self.visit_call_expr_inner(e, allow_none_return=allow_none_return)
File "/home/njs/.user-python3.7/lib/python3.7/site-packages/mypy/checkexpr.py", line 279, in visit_call_expr_inner
callee_type = self.accept(e.callee, type_context, always_allow_any=True)
File "/home/njs/.user-python3.7/lib/python3.7/site-packages/mypy/checkexpr.py", line 3259, in accept
typ = node.accept(self)
File "/home/njs/.user-python3.7/lib/python3.7/site-packages/mypy/nodes.py", line 1470, in accept
return visitor.visit_member_expr(self)
File "/home/njs/.user-python3.7/lib/python3.7/site-packages/mypy/checkexpr.py", line 1751, in visit_member_expr
result = self.analyze_ordinary_member_access(e, is_lvalue)
File "/home/njs/.user-python3.7/lib/python3.7/site-packages/mypy/checkexpr.py", line 1766, in analyze_ordinary_member_access
in_literal_context=self.is_literal_context())
File "/home/njs/.user-python3.7/lib/python3.7/site-packages/mypy/checkmember.py", line 103, in analyze_member_access
result = _analyze_member_access(name, typ, mx, override_info)
File "/home/njs/.user-python3.7/lib/python3.7/site-packages/mypy/checkmember.py", line 117, in _analyze_member_access
return analyze_instance_member_access(name, typ, mx, override_info)
File "/home/njs/.user-python3.7/lib/python3.7/site-packages/mypy/checkmember.py", line 187, in analyze_instance_member_access
typ = map_instance_to_supertype(typ, method.info)
File "/home/njs/.user-python3.7/lib/python3.7/site-packages/mypy/maptype.py", line 20, in map_instance_to_supertype
if not superclass.type_vars:
File "/home/njs/.user-python3.7/lib/python3.7/site-packages/mypy/nodes.py", line 2600, in __getattribute__
raise AssertionError(object.__getattribute__(self, 'msg'))
AssertionError: FuncBase for non-methods lack info
/tmp/b.py:5: : note: use --pdb to drop into pdb
(Yes this is silly. I have a class where some methods are hand-written and some are output by a code generator, so the idea is that a.py
is generated and then b.py
assembles the generated and hand-written bits together into a class.)