Skip to content
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

typing.get_type_hints cannot resolve forward references in cls.__init__ annotations #1021

Open
mwchase opened this issue Sep 5, 2022 · 1 comment
Labels
Typing Typing/stub/Mypy/PyRight related bugs.

Comments

@mwchase
Copy link

mwchase commented Sep 5, 2022

The is related to #593/#760. Because #760 populates the generated __init__ method's globals at the time that the class is created, new globals aren't visible to get_type_hints by default.

Example code demonstrating this:

import attrs
import typing

@attrs.define
class HasForwardRef:
    ref: "ClassDefinedLater"

class ClassDefinedLater:
    pass

typing.get_type_hints(HasForwardRef.__init__)

This last call raises an error.

I've got a workaround for this in the code where I hit this, but it really wasn't obvious at first what was going on.

@hynek
Copy link
Member

hynek commented Sep 16, 2022

I'm not sure what to do about this – is it fixable yet at all?

@hynek hynek added the Typing Typing/stub/Mypy/PyRight related bugs. label Dec 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Typing Typing/stub/Mypy/PyRight related bugs.
Projects
None yet
Development

No branches or pull requests

2 participants