Closed
Description
Mypy crashes when inferring the call to f
below:
from typing import Union, Callable, Match, TypeVar
T = TypeVar('T')
def f(x: T, y: Union[T, Callable[[T], None]]) -> None: pass
f('', '')
The above is about the simplest signature that seems to trigger the bug. In practice, a signature for re.sub
also causes the crash (see #665).
Here's the traceback:
Traceback (most recent call last):
File "scripts/mypy", line 182, in <module>
main()
File "scripts/mypy", line 36, in main
type_check_only(path, module, bin_dir, options)
File "scripts/mypy", line 80, in type_check_only
python_path=options.python_path)
File "/home/jukka/project/mypy/mypy/build.py", line 164, in build
result = manager.process(UnprocessedFile(info, program_text))
File "/home/jukka/project/mypy/mypy/build.py", line 341, in process
next.process()
File "/home/jukka/project/mypy/mypy/build.py", line 814, in process
self.type_checker().visit_file(self.tree, self.tree.path)
File "/home/jukka/project/mypy/mypy/checker.py", line 350, in visit_file
self.accept(d)
File "/home/jukka/project/mypy/mypy/checker.py", line 357, in accept
typ = node.accept(self)
File "/home/jukka/project/mypy/mypy/nodes.py", line 519, in accept
return visitor.visit_expression_stmt(self)
File "/home/jukka/project/mypy/mypy/checker.py", line 1302, in visit_expression_stmt
self.accept(s.expr)
File "/home/jukka/project/mypy/mypy/checker.py", line 357, in accept
typ = node.accept(self)
File "/home/jukka/project/mypy/mypy/nodes.py", line 938, in accept
return visitor.visit_call_expr(self)
File "/home/jukka/project/mypy/mypy/checker.py", line 1709, in visit_call_expr
result = self.expr_checker.visit_call_expr(e)
File "/home/jukka/project/mypy/mypy/checkexpr.py", line 118, in visit_call_expr
return self.check_call_expr_with_callee_type(callee_type, e)
File "/home/jukka/project/mypy/mypy/checkexpr.py", line 128, in check_call_expr_with_callee_type
e.arg_names, callable_node=e.callee)[0]
File "/home/jukka/project/mypy/mypy/checkexpr.py", line 171, in check_call
callee, args, arg_kinds, formal_to_actual, context)
File "/home/jukka/project/mypy/mypy/checkexpr.py", line 351, in infer_function_type_arguments
callee_type, pass1_args, arg_kinds, formal_to_actual) # type: List[Type]
File "/home/jukka/project/mypy/mypy/infer.py", line 33, in infer_function_type_arguments
return solve_constraints(type_vars, constraints)
File "/home/jukka/project/mypy/mypy/solve.py", line 41, in solve_constraints
bottom = join_types(bottom, c.target)
File "/home/jukka/project/mypy/mypy/join.py", line 68, in join_types
return t.accept(TypeJoinVisitor(s))
AttributeError: 'NoneType' object has no attribute 'accept'