Skip to content

Internal error when using reveal_locals() inside class that contains an inner class #5915

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
mthuurne opened this issue Nov 19, 2018 · 1 comment · Fixed by #5920
Closed

Comments

@mthuurne
Copy link
Contributor

While trying to dig deeper on #5914, I ran into an internal error in mypy.

I ran mypy on this code, without any arguments other than the file name:

class Outer:
    class Inner:
        pass
    reveal_locals()

This is the traceback: (paths shortened)

Traceback (most recent call last):
  File ".../bin/mypy", line 11, in <module>
    sys.exit(console_entry())
  File ".../lib/python3.6/site-packages/mypy/__main__.py", line 7, in console_entry
    main(None)
  File ".../lib/python3.6/site-packages/mypy/main.py", line 92, in main
    res = build.build(sources, options, None, flush_errors, fscache)
  File ".../lib/python3.6/site-packages/mypy/build.py", line 155, in build
    result = _build(sources, options, alt_lib_path, flush_errors, fscache)
  File ".../lib/python3.6/site-packages/mypy/build.py", line 204, in _build
    graph = dispatch(sources, manager)
  File ".../lib/python3.6/site-packages/mypy/build.py", line 2172, in dispatch
    process_graph(graph, manager)
  File ".../lib/python3.6/site-packages/mypy/build.py", line 2469, in process_graph
    process_stale_scc(graph, scc, manager)
  File ".../lib/python3.6/site-packages/mypy/build.py", line 2592, in process_stale_scc
    graph[id].type_check_first_pass()
  File ".../lib/python3.6/site-packages/mypy/build.py", line 1730, in type_check_first_pass
    self.type_checker().check_first_pass()
  File ".../lib/python3.6/site-packages/mypy/checker.py", line 282, in check_first_pass
    self.accept(d)
  File ".../lib/python3.6/site-packages/mypy/checker.py", line 393, in accept
    stmt.accept(self)
  File ".../lib/python3.6/site-packages/mypy/nodes.py", line 845, in accept
    return visitor.visit_class_def(self)
  File ".../lib/python3.6/site-packages/mypy/checker.py", line 1536, in visit_class_def
    self.accept(defn.defs)
  File ".../lib/python3.6/site-packages/mypy/checker.py", line 393, in accept
    stmt.accept(self)
  File ".../lib/python3.6/site-packages/mypy/nodes.py", line 910, in accept
    return visitor.visit_block(self)
  File ".../lib/python3.6/site-packages/mypy/checker.py", line 1688, in visit_block
    self.accept(s)
  File ".../lib/python3.6/site-packages/mypy/checker.py", line 393, in accept
    stmt.accept(self)
  File ".../lib/python3.6/site-packages/mypy/nodes.py", line 925, in accept
    return visitor.visit_expression_stmt(self)
  File ".../lib/python3.6/site-packages/mypy/checker.py", line 2602, in visit_expression_stmt
    self.expr_checker.accept(s.expr, allow_none_return=True, always_allow_any=True)
  File ".../lib/python3.6/site-packages/mypy/checkexpr.py", line 3003, in accept
    typ = self.visit_call_expr(node, allow_none_return=True)
  File ".../lib/python3.6/site-packages/mypy/checkexpr.py", line 228, in visit_call_expr
    return self.accept(e.analyzed, self.type_context[-1])
  File ".../lib/python3.6/site-packages/mypy/checkexpr.py", line 3007, in accept
    typ = node.accept(self)
  File ".../lib/python3.6/site-packages/mypy/nodes.py", line 1674, in accept
    return visitor.visit_reveal_expr(self)
  File ".../lib/python3.6/site-packages/mypy/checkexpr.py", line 2362, in visit_reveal_expr
    } if expr.local_nodes is not None else {}
  File ".../lib/python3.6/site-packages/mypy/checkexpr.py", line 2361, in <dictcomp>
    var_node.name(): var_node.type for var_node in expr.local_nodes
AttributeError: 'TypeInfo' object has no attribute 'type'

I'm using mypy 0.641 on Python 3.6.5.

@gvanrossum
Copy link
Member

This is due to improper casting in semanal.py where local_nodes is computed. I can quickly fix there.

@gvanrossum gvanrossum self-assigned this Nov 19, 2018
gvanrossum pushed a commit to gvanrossum/mypy that referenced this issue Nov 20, 2018
gvanrossum added a commit that referenced this issue Nov 20, 2018
The root cause were some improper casts when creating the `local_nodes` list. These were easy to fix by adding `isinstance(node, Var)` checks to the list comprehensions.

Fixes #5915
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