Skip to content

RuntimeError: Internal error: unresolved forward reference #4376

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
gvanrossum opened this issue Dec 16, 2017 · 5 comments
Closed

RuntimeError: Internal error: unresolved forward reference #4376

gvanrossum opened this issue Dec 16, 2017 · 5 comments

Comments

@gvanrossum
Copy link
Member

We got the same exception as #4370 (though with a somewhat different traceback). The user sent me a repro (which I have not managed to confirm):

class BaseClass(object):
    def some_method(self):
        # type: () -> BaseClass
        pass
class SubClass1(BaseClass):
    def some_method(self):
        # type: () -> AnotherNameForSubClass1  # <--- Forward ref to alias causes crash
        pass
AnotherNameForSubClass1 = SubClass1

The traceback ended in:

File "/Users/xxx/src/server/.mypy/venv/lib/python3.5/site-packages/mypy/checker.py", line 2101, in visit_return_stmt
self.check_return_stmt(s)
File "/Users/xxx/src/server/.mypy/venv/lib/python3.5/site-packages/mypy/checker.py", line 2132, in check_return_stmt
allow_none_return=allow_none_func_call)
File "/Users/xxx/src/server/.mypy/venv/lib/python3.5/site-packages/mypy/checkexpr.py", line 2365, in accept
typ = node.accept(self)
File "/Users/xxx/src/server/.mypy/venv/lib/python3.5/site-packages/mypy/nodes.py", line 1245, in accept
return visitor.visit_call_expr(self)
File "/Users/xxx/src/server/.mypy/venv/lib/python3.5/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 "/Users/xxx/src/server/.mypy/venv/lib/python3.5/site-packages/mypy/checkexpr.py", line 505, in check_call_expr_with_callee_type
object_type=object_type)[0]
File "/Users/xxx/src/server/.mypy/venv/lib/python3.5/site-packages/mypy/checkexpr.py", line 578, in check_call
messages=arg_messages)
File "/Users/xxx/src/server/.mypy/venv/lib/python3.5/site-packages/mypy/checkexpr.py", line 1048, in check_argument_types
actual + 1, i + 1, callee, context, messages)
File "/Users/xxx/src/server/.mypy/venv/lib/python3.5/site-packages/mypy/checkexpr.py", line 1080, in check_arg
elif not is_subtype(caller_type, callee_type):
File "/Users/xxx/src/server/.mypy/venv/lib/python3.5/site-packages/mypy/subtypes.py", line 83, in is_subtype
ignore_declared_variance=ignore_declared_variance))
File "/Users/xxx/src/server/.mypy/venv/lib/python3.5/site-packages/mypy/types.py", line 1415, in accept
    return visitor.visit_forwardref_type(self)
  File "/Users/xxx/src/server/.mypy/venv/lib/python3.5/site-packages/mypy/types.py", line 1500, in visit_forwardref_type
    raise RuntimeError('Internal error: unresolved forward reference')
RuntimeError: Internal error: unresolved forward reference

However there must be something else because the test program does not repro the crash.

@mitar
Copy link

mitar commented Dec 19, 2017

Maybe related: #4385

@gvanrossum
Copy link
Member Author

FWIW another report of this came in. The code was something like this

class SomeClass(object):
    def foo(self):
        # type: () -> SomeNamedTuple
SomeNamedTuple = NamedTuple('SomeNamedTuple', [('bar', List[SomeClass])])

The fix was to move the named tuple before the class.

@ilevkivskyi
Copy link
Member

This particular code however doesn't crash, there must some additional ingredient for the crash. I tried to play with --incremental, but still not able to reproduce.

@gvanrossum
Copy link
Member Author

It wasn't due to --incremental I think, since the initial cache is empty in our internal builds. Check out the full diff which was disclosed to you internally.

@gvanrossum
Copy link
Member Author

Confirmed that this crash is gone with the latest mypy.

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

3 participants