Skip to content

Crash due to unresolved forward reference to decorated method #4383

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
JukkaL opened this issue Dec 18, 2017 · 3 comments
Closed

Crash due to unresolved forward reference to decorated method #4383

JukkaL opened this issue Dec 18, 2017 · 3 comments

Comments

@JukkaL
Copy link
Collaborator

JukkaL commented Dec 18, 2017

Mypy crashes when type checking this program:

from typing import NewType

N = NewType('N', XXX)

b = C.g()

class C:
    @staticmethod
    def g() -> N:
        pass

If I replace @staticmethod with another decorator the crash persists.

Here's the traceback:

$ mypy --show-traceback t/t2.py
t/t2.py:3: error: Argument 2 to NewType(...) must be subclassable (got "Any")
t/t2.py:3: error: Name 'XXX' is not defined
t/t2.py:9: error: Invalid type "t2.N"
t/t2.py:5: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.560-dev-ba615b74f07c92221f264f7a6a5375be0a41ebed
Traceback (most recent call last):
  File "/Users/jukka/src/mypy/scripts/mypy", line 6, in <module>
    main(__file__)
  File "/Users/jukka/src/mypy/mypy/main.py", line 66, in main
    res = type_check_only(sources, bin_dir, options)
  File "/Users/jukka/src/mypy/mypy/main.py", line 119, in type_check_only
    options=options)
  File "/Users/jukka/src/mypy/mypy/build.py", line 218, in build
    graph = dispatch(sources, manager)
  File "/Users/jukka/src/mypy/mypy/build.py", line 2001, in dispatch
    process_graph(graph, manager)
  File "/Users/jukka/src/mypy/mypy/build.py", line 2305, in process_graph
    process_stale_scc(graph, scc, manager)
  File "/Users/jukka/src/mypy/mypy/build.py", line 2481, in process_stale_scc
    graph[id].type_check_first_pass()
  File "/Users/jukka/src/mypy/mypy/build.py", line 1880, in type_check_first_pass
    self.type_checker().check_first_pass()
  File "/Users/jukka/src/mypy/mypy/checker.py", line 200, in check_first_pass
    self.accept(d)
  File "/Users/jukka/src/mypy/mypy/checker.py", line 295, in accept
    stmt.accept(self)
  File "/Users/jukka/src/mypy/mypy/nodes.py", line 805, in accept
    return visitor.visit_assignment_stmt(self)
  File "/Users/jukka/src/mypy/mypy/checker.py", line 1350, in visit_assignment_stmt
    self.check_assignment(s.lvalues[-1], s.rvalue, s.type is None, s.new_syntax)
  File "/Users/jukka/src/mypy/mypy/checker.py", line 1445, in check_assignment
    rvalue)
  File "/Users/jukka/src/mypy/mypy/checker.py", line 1909, in infer_variable_type
    elif not is_valid_inferred_type(init_type) and not self.no_partial_types:
  File "/Users/jukka/src/mypy/mypy/checker.py", line 3441, in is_valid_inferred_type
    return is_valid_inferred_type_component(typ)
  File "/Users/jukka/src/mypy/mypy/checker.py", line 3450, in is_valid_inferred_type_component
    if is_same_type(typ, UninhabitedType()):
  File "/Users/jukka/src/mypy/mypy/sametypes.py", line 28, in is_same_type
    return left.accept(SameTypeVisitor(right))
  File "/Users/jukka/src/mypy/mypy/types.py", line 1415, in accept
    return visitor.visit_forwardref_type(self)
  File "/Users/jukka/src/mypy/mypy/types.py", line 1500, in visit_forwardref_type
    raise RuntimeError('Internal error: unresolved forward reference')
RuntimeError: Internal error: unresolved forward reference
t/t2.py:5: : note: use --pdb to drop into pdb

This seems related to #4200 but the same fix doesn't seem to work.

@JukkaL
Copy link
Collaborator Author

JukkaL commented Dec 18, 2017

Actually this doesn't happen on master .. it must be caused by my local changes.

@JukkaL JukkaL closed this as completed Dec 18, 2017
@ilevkivskyi
Copy link
Member

Yes, this was fixed by #4375

@JukkaL
Copy link
Collaborator Author

JukkaL commented Dec 18, 2017

Yes, I hadn't rebased in a few days.

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

2 participants