Skip to content

INTERNAL ERROR reported by mypy 0.610 #5291

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
andymwood opened this issue Jun 28, 2018 · 2 comments
Closed

INTERNAL ERROR reported by mypy 0.610 #5291

andymwood opened this issue Jun 28, 2018 · 2 comments

Comments

@andymwood
Copy link

I'm getting an internal error when testing some code I'm trying to patch.

I've been unable to reproduce the problem with a trivial example, so I've pushed the changes to my GitHub profile.

To reproduce:

git clone [email protected]:andymwood/numpy-stubs.git
cd numpy-stubs
git checkout annotations       # Currently on commit 33496555
pip install .
mypy --strict tests/pass/simple.py

which produces the following output:

tests/pass/simple.py:76: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.610
tests/pass/simple.py:76: : note: please use --show-traceback to print a traceback when reporting a bug

Here's the traceback:

Traceback (most recent call last):
  File "/home/andrew/.conda/envs/numpy-stubs/bin/mypy", line 11, in <module>
    sys.exit(console_entry())
  File "/home/andrew/.conda/envs/numpy-stubs/lib/python3.6/site-packages/mypy/__main__.py", line 7, in console_entry
    main(None)
  File "/home/andrew/.conda/envs/numpy-stubs/lib/python3.6/site-packages/mypy/main.py", line 91, in main
    res = type_check_only(sources, bin_dir, options, flush_errors, fscache)  # noqa
  File "/home/andrew/.conda/envs/numpy-stubs/lib/python3.6/site-packages/mypy/main.py", line 148, in type_check_only
    fscache=fscache)
  File "/home/andrew/.conda/envs/numpy-stubs/lib/python3.6/site-packages/mypy/build.py", line 185, in build
    flush_errors, fscache)
  File "/home/andrew/.conda/envs/numpy-stubs/lib/python3.6/site-packages/mypy/build.py", line 285, in _build
    graph = dispatch(sources, manager)
  File "/home/andrew/.conda/envs/numpy-stubs/lib/python3.6/site-packages/mypy/build.py", line 2398, in dispatch
    process_graph(graph, manager)
  File "/home/andrew/.conda/envs/numpy-stubs/lib/python3.6/site-packages/mypy/build.py", line 2691, in process_graph
    process_stale_scc(graph, scc, manager)
  File "/home/andrew/.conda/envs/numpy-stubs/lib/python3.6/site-packages/mypy/build.py", line 2807, in process_stale_scc
    graph[id].type_check_first_pass()
  File "/home/andrew/.conda/envs/numpy-stubs/lib/python3.6/site-packages/mypy/build.py", line 2029, in type_check_first_pass
    self.type_checker().check_first_pass()
  File "/home/andrew/.conda/envs/numpy-stubs/lib/python3.6/site-packages/mypy/checker.py", line 252, in check_first_pass
    self.accept(d)
  File "/home/andrew/.conda/envs/numpy-stubs/lib/python3.6/site-packages/mypy/checker.py", line 351, in accept
    stmt.accept(self)
  File "/home/andrew/.conda/envs/numpy-stubs/lib/python3.6/site-packages/mypy/nodes.py", line 883, in accept
    return visitor.visit_expression_stmt(self)
  File "/home/andrew/.conda/envs/numpy-stubs/lib/python3.6/site-packages/mypy/checker.py", line 2237, in visit_expression_stmt
    self.expr_checker.accept(s.expr, allow_none_return=True, always_allow_any=True)
  File "/home/andrew/.conda/envs/numpy-stubs/lib/python3.6/site-packages/mypy/checkexpr.py", line 2407, in accept
    typ = node.accept(self)
  File "/home/andrew/.conda/envs/numpy-stubs/lib/python3.6/site-packages/mypy/nodes.py", line 1543, in accept
    return visitor.visit_op_expr(self)
  File "/home/andrew/.conda/envs/numpy-stubs/lib/python3.6/site-packages/mypy/checkexpr.py", line 1396, in visit_op_expr
    allow_reverse=True)
  File "/home/andrew/.conda/envs/numpy-stubs/lib/python3.6/site-packages/mypy/checkexpr.py", line 1523, in check_op
    local_errors)
  File "/home/andrew/.conda/envs/numpy-stubs/lib/python3.6/site-packages/mypy/checkexpr.py", line 1507, in check_op_local
    callable_name=callable_name, object_type=object_type)
  File "/home/andrew/.conda/envs/numpy-stubs/lib/python3.6/site-packages/mypy/checkexpr.py", line 577, in check_call
    callee, args, arg_kinds, formal_to_actual, context)
  File "/home/andrew/.conda/envs/numpy-stubs/lib/python3.6/site-packages/mypy/checkexpr.py", line 829, in infer_function_type_arguments
    strict=self.chk.in_checked_function())
  File "/home/andrew/.conda/envs/numpy-stubs/lib/python3.6/site-packages/mypy/infer.py", line 31, in infer_function_type_arguments
    callee_type, arg_types, arg_kinds, formal_to_actual)
  File "/home/andrew/.conda/envs/numpy-stubs/lib/python3.6/site-packages/mypy/constraints.py", line 63, in infer_constraints_for_callable
    SUPERTYPE_OF)
  File "/home/andrew/.conda/envs/numpy-stubs/lib/python3.6/site-packages/mypy/constraints.py", line 170, in infer_constraints
    for t_item in template.items],
  File "/home/andrew/.conda/envs/numpy-stubs/lib/python3.6/site-packages/mypy/constraints.py", line 170, in <listcomp>
    for t_item in template.items],
  File "/home/andrew/.conda/envs/numpy-stubs/lib/python3.6/site-packages/mypy/constraints.py", line 190, in infer_constraints_if_possible
    return infer_constraints(template, actual, direction)
  File "/home/andrew/.conda/envs/numpy-stubs/lib/python3.6/site-packages/mypy/constraints.py", line 174, in infer_constraints
    return template.accept(ConstraintBuilderVisitor(actual, direction))
  File "/home/andrew/.conda/envs/numpy-stubs/lib/python3.6/site-packages/mypy/types.py", line 512, in accept
    return visitor.visit_instance(self)
  File "/home/andrew/.conda/envs/numpy-stubs/lib/python3.6/site-packages/mypy/constraints.py", line 351, in visit_instance
    original_actual, template)
  File "/home/andrew/.conda/envs/numpy-stubs/lib/python3.6/site-packages/mypy/constraints.py", line 393, in infer_constraints_from_protocol_members
    assert inst is not None and temp is not None
AssertionError:
@ilevkivskyi
Copy link
Member

OK, I think I identified the cause: it is _promote. A simple repro is:

from typing import SupportsComplex, TypeVar, Union

T = TypeVar('T')

def f(x: Union[SupportsComplex, T]) -> Union[SupportsComplex, T]: ...

f(0)

For example in this particular case int doesn't implement SupportsComplex protocol, but it is considered a subtype of it because int is promoted to float, and then to complex. Then in the constraint inference code we assume that "if it is a subtype of a protocol, then it must have all members", which is not the case here.

A potential solution is to replace is_subtype with is_protocol_implementation in that protocol constraint inference branch.

@ilevkivskyi
Copy link
Member

I actually think it is relatively important and the fix may be simple so I set priority to high.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants