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

Does not work with annotation string #2

Open
Horstage opened this issue Jun 25, 2019 · 2 comments
Open

Does not work with annotation string #2

Horstage opened this issue Jun 25, 2019 · 2 comments

Comments

@Horstage
Copy link

Type annotations can be Strings and with Python 4.0 will always be handled as such (PEP 484).
As of Python 3.7 you can from __future__ import annotations to replicated Py4.0 behavior.
This package does not work with strings as annotation.

I already stumbled on this.
Referencing to parent or child objects of the same class is rather common (I believe)

from typing import Optional
class Foo:
    bar: int # works fine
    baz: "str"  # does not work, but you could simply remove quotation marks for now
    child: "Optional[MyClass]"  # does not work
    parent: "Optional[MyClass]"

The only solution I see right now is to use eval on the annotations. Please prove me wrong.

@Horstage
Copy link
Author

Further investigation show that you could get the type hints via typing.get_type_hints(Foo).

@rhbvkleef
Copy link
Owner

Oh, I don't like this... I can see why they're doing this, but it makes things a bi tharder. Thanks for letting me know :)

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