Skip to content

Report of INTERNAL ERROR with minimal reproduction #4649

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
evhub opened this issue Feb 28, 2018 · 2 comments · Fixed by #5433
Closed

Report of INTERNAL ERROR with minimal reproduction #4649

evhub opened this issue Feb 28, 2018 · 2 comments · Fixed by #5433

Comments

@evhub
Copy link
Contributor

evhub commented Feb 28, 2018

The following code snippet

from functools import reduce
M = Iterable
def f(m1: M, m2):
    ...
def g(ms: T[M]) -> None:
    reduce(f, ms)
T = Iterable

when run through mypy --show-traceback on version 0.560 produces the following traceback

.\break_mypy.py:22: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.560
Traceback (most recent call last):
  File "c:\anaconda3\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\anaconda3\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Anaconda3\Scripts\mypy.exe\__main__.py", line 9, in <module>
    sys.exit(console_entry())
  File "c:\anaconda3\lib\site-packages\mypy\__main__.py", line 7, in console_entry
    main(None)
  File "c:\anaconda3\lib\site-packages\mypy\main.py", line 66, in main
    res = type_check_only(sources, bin_dir, options)
  File "c:\anaconda3\lib\site-packages\mypy\main.py", line 119, in type_check_only
    options=options)
  File "c:\anaconda3\lib\site-packages\mypy\build.py", line 218, in build
    graph = dispatch(sources, manager)
  File "c:\anaconda3\lib\site-packages\mypy\build.py", line 1997, in dispatch
    process_graph(graph, manager)
  File "c:\anaconda3\lib\site-packages\mypy\build.py", line 2299, in process_graph
    process_stale_scc(graph, scc, manager)
  File "c:\anaconda3\lib\site-packages\mypy\build.py", line 2475, in process_stale_scc
    graph[id].type_check_first_pass()
  File "c:\anaconda3\lib\site-packages\mypy\build.py", line 1876, in type_check_first_pass
    self.type_checker().check_first_pass()
  File "c:\anaconda3\lib\site-packages\mypy\checker.py", line 196, in check_first_pass
    self.accept(d)
  File "c:\anaconda3\lib\site-packages\mypy\checker.py", line 286, in accept
    stmt.accept(self)
  File "c:\anaconda3\lib\site-packages\mypy\nodes.py", line 497, in accept
    return visitor.visit_func_def(self)
  File "c:\anaconda3\lib\site-packages\mypy\checker.py", line 534, in visit_func_def
    self.check_func_item(defn, name=defn.name())
  File "c:\anaconda3\lib\site-packages\mypy\checker.py", line 599, in check_func_item
    self.check_func_def(defn, typ, name)
  File "c:\anaconda3\lib\site-packages\mypy\checker.py", line 762, in check_func_def
    self.accept(item.body)
  File "c:\anaconda3\lib\site-packages\mypy\checker.py", line 286, in accept
    stmt.accept(self)
  File "c:\anaconda3\lib\site-packages\mypy\nodes.py", line 756, in accept
    return visitor.visit_block(self)
  File "c:\anaconda3\lib\site-packages\mypy\checker.py", line 1330, in visit_block
    self.accept(s)
  File "c:\anaconda3\lib\site-packages\mypy\checker.py", line 286, in accept
    stmt.accept(self)
  File "c:\anaconda3\lib\site-packages\mypy\nodes.py", line 770, in accept
    return visitor.visit_expression_stmt(self)
  File "c:\anaconda3\lib\site-packages\mypy\checker.py", line 2097, in visit_expression_stmt
    self.expr_checker.accept(s.expr, allow_none_return=True, always_allow_any=True)
  File "c:\anaconda3\lib\site-packages\mypy\checkexpr.py", line 2361, in accept
    typ = self.visit_call_expr(node, allow_none_return=True)
  File "c:\anaconda3\lib\site-packages\mypy\checkexpr.py", line 268, in visit_call_expr
    ret_type = self.check_call_expr_with_callee_type(callee_type, e, fullname, object_type)
  File "c:\anaconda3\lib\site-packages\mypy\checkexpr.py", line 505, in check_call_expr_with_callee_type
    object_type=object_type)[0]
  File "c:\anaconda3\lib\site-packages\mypy\checkexpr.py", line 611, in check_call
    object_type=object_type)
  File "c:\anaconda3\lib\site-packages\mypy\checkexpr.py", line 568, in check_call
    callee, args, arg_kinds, formal_to_actual, context)
  File "c:\anaconda3\lib\site-packages\mypy\checkexpr.py", line 823, in infer_function_type_arguments
    inferred_args, context)
  File "c:\anaconda3\lib\site-packages\mypy\checkexpr.py", line 877, in infer_function_type_arguments_pass2
    callee_type, arg_types, arg_kinds, formal_to_actual)
  File "c:\anaconda3\lib\site-packages\mypy\infer.py", line 31, in infer_function_type_arguments
    callee_type, arg_types, arg_kinds, formal_to_actual)
  File "c:\anaconda3\lib\site-packages\mypy\constraints.py", line 63, in infer_constraints_for_callable
    SUPERTYPE_OF)
  File "c:\anaconda3\lib\site-packages\mypy\constraints.py", line 174, in infer_constraints
    return template.accept(ConstraintBuilderVisitor(actual, direction))
  File "c:\anaconda3\lib\site-packages\mypy\types.py", line 739, in accept
    return visitor.visit_callable_type(self)
  File "c:\anaconda3\lib\site-packages\mypy\constraints.py", line 415, in visit_callable_type
    res.extend(infer_constraints(t, a, neg_op(self.direction)))
  File "c:\anaconda3\lib\site-packages\mypy\constraints.py", line 174, in infer_constraints
    return template.accept(ConstraintBuilderVisitor(actual, direction))
  File "c:\anaconda3\lib\site-packages\mypy\types.py", line 475, in accept
    return visitor.visit_instance(self)
  File "c:\anaconda3\lib\site-packages\mypy\constraints.py", line 326, in visit_instance
    mapped.args[i], instance.args[i], self.direction))
IndexError: list index out of range
.\break_mypy.py:22: : note: use --pdb to drop into pdb
@gvanrossum
Copy link
Member

Confirmed (the snippet also needs from typing import Iterable for it to be a repro).

@ilevkivskyi
Copy link
Member

I think that checks that are done in third pass don't happen for types that are forward references: most importantly, checking the correct number of type arguments. I.e. my guess is that T[M] is expanded to Iterable[Iterable], while it should expand to Iterable[Iterable[Any]].

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

Successfully merging a pull request may close this issue.

3 participants