Skip to content

Crash on super call in function with type variable #2361

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
ddfisher opened this issue Oct 28, 2016 · 4 comments
Closed

Crash on super call in function with type variable #2361

ddfisher opened this issue Oct 28, 2016 · 4 comments

Comments

@ddfisher
Copy link
Collaborator

#2193 causes a crash when calling super in function which takes a generic argument (even if the generic argument is unused). Here's the minimum reproducer I've found:

from typing import TypeVar

T = TypeVar('T', int, str)

class A:
    pass

class B(A):
    def __init__(self, arg):
        # type: (T) -> None
        super(B, self).__init__()

@JukkaL @elazarg could you take a look?

@ddfisher
Copy link
Collaborator Author

Here's the traceback (it's for the last line of the file):

Traceback (most recent call last):
  File "/usr/local/Cellar/python3/3.5.2_1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/runpy.py", line 184, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/local/Cellar/python3/3.5.2_1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/Users/ddfisher/src/mypy/mypy/__main__.py", line 5, in <module>
    main(None)
  File "/Users/ddfisher/src/mypy/mypy/main.py", line 41, in main
    res = type_check_only(sources, bin_dir, options)
  File "/Users/ddfisher/src/mypy/mypy/main.py", line 86, in type_check_only
    options=options)
  File "/Users/ddfisher/src/mypy/mypy/build.py", line 180, in build
    dispatch(sources, manager)
  File "/Users/ddfisher/src/mypy/mypy/build.py", line 1509, in dispatch
    process_graph(graph, manager)
  File "/Users/ddfisher/src/mypy/mypy/build.py", line 1689, in process_graph
    process_stale_scc(graph, scc)
  File "/Users/ddfisher/src/mypy/mypy/build.py", line 1768, in process_stale_scc
    graph[id].type_check_first_pass()
  File "/Users/ddfisher/src/mypy/mypy/build.py", line 1437, in type_check_first_pass
    self.type_checker.check_first_pass()
  File "/Users/ddfisher/src/mypy/mypy/checker.py", line 178, in check_first_pass
    self.accept(d)
  File "/Users/ddfisher/src/mypy/mypy/checker.py", line 237, in accept
    typ = node.accept(self)
  File "/Users/ddfisher/src/mypy/mypy/nodes.py", line 709, in accept
    return visitor.visit_class_def(self)
  File "/Users/ddfisher/src/mypy/mypy/checker.py", line 977, in visit_class_def
    self.accept(defn.defs)
  File "/Users/ddfisher/src/mypy/mypy/checker.py", line 237, in accept
    typ = node.accept(self)
  File "/Users/ddfisher/src/mypy/mypy/nodes.py", line 770, in accept
    return visitor.visit_block(self)
  File "/Users/ddfisher/src/mypy/mypy/checker.py", line 1069, in visit_block
    self.accept(s)
  File "/Users/ddfisher/src/mypy/mypy/checker.py", line 237, in accept
    typ = node.accept(self)
  File "/Users/ddfisher/src/mypy/mypy/nodes.py", line 531, in accept
    return visitor.visit_func_def(self)
  File "/Users/ddfisher/src/mypy/mypy/checker.py", line 448, in visit_func_def
    self.check_func_item(defn, name=defn.name())
  File "/Users/ddfisher/src/mypy/mypy/checker.py", line 511, in check_func_item
    self.check_func_def(defn, typ, name)
  File "/Users/ddfisher/src/mypy/mypy/checker.py", line 633, in check_func_def
    self.accept(item.body)
  File "/Users/ddfisher/src/mypy/mypy/checker.py", line 237, in accept
    typ = node.accept(self)
  File "/Users/ddfisher/src/mypy/mypy/nodes.py", line 770, in accept
    return visitor.visit_block(self)
  File "/Users/ddfisher/src/mypy/mypy/checker.py", line 1069, in visit_block
    self.accept(s)
  File "/Users/ddfisher/src/mypy/mypy/checker.py", line 237, in accept
    typ = node.accept(self)
  File "/Users/ddfisher/src/mypy/mypy/nodes.py", line 784, in accept
    return visitor.visit_expression_stmt(self)
  File "/Users/ddfisher/src/mypy/mypy/checker.py", line 1502, in visit_expression_stmt
    self.accept(s.expr)
  File "/Users/ddfisher/src/mypy/mypy/checker.py", line 237, in accept
    typ = node.accept(self)
  File "/Users/ddfisher/src/mypy/mypy/nodes.py", line 1246, in accept
    return visitor.visit_call_expr(self)
  File "/Users/ddfisher/src/mypy/mypy/checker.py", line 1933, in visit_call_expr
    return self.expr_checker.visit_call_expr(e)
  File "/Users/ddfisher/src/mypy/mypy/checkexpr.py", line 170, in visit_call_expr
    callee_type = self.accept(e.callee)
  File "/Users/ddfisher/src/mypy/mypy/checkexpr.py", line 1759, in accept
    return self.chk.accept(node, context)
  File "/Users/ddfisher/src/mypy/mypy/checker.py", line 237, in accept
    typ = node.accept(self)
  File "/Users/ddfisher/src/mypy/mypy/nodes.py", line 1474, in accept
    return visitor.visit_super_expr(self)
  File "/Users/ddfisher/src/mypy/mypy/checker.py", line 2069, in visit_super_expr
    return self.expr_checker.visit_super_expr(e)
  File "/Users/ddfisher/src/mypy/mypy/checkexpr.py", line 1587, in visit_super_expr
    t = self.analyze_super(e, False)
  File "/Users/ddfisher/src/mypy/mypy/checkexpr.py", line 1617, in analyze_super
    original_type=declared_self)
  File "/Users/ddfisher/src/mypy/mypy/checkmember.py", line 185, in analyze_member_access
    return msg.has_no_attr(original_type, name, node)
  File "/Users/ddfisher/src/mypy/mypy/messages.py", line 355, in has_no_attr
    self.fail('{} has no attribute "{}"'.format(self.format(typ),
  File "/Users/ddfisher/src/mypy/mypy/messages.py", line 150, in format
    s = self.format_simple(typ, verbosity)
  File "/Users/ddfisher/src/mypy/mypy/messages.py", line 269, in format_simple
    raise RuntimeError('Type is None')
RuntimeError: Type is None

@elazarg
Copy link
Contributor

elazarg commented Oct 28, 2016

Ouch. I think it's what we discussed here. But I will dig deeper.

@elazarg
Copy link
Contributor

elazarg commented Oct 28, 2016

Reverting mypy/checkexpr:1612 to typ=fill_typevars(e.info) avoids the crash. Of course it doesn't mean that's the right fix.

@JukkaL
Copy link
Collaborator

JukkaL commented Jan 16, 2017

This seems to work now.

@JukkaL JukkaL closed this as completed Jan 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants