-
Notifications
You must be signed in to change notification settings - Fork 587
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
from_type() does not resolve forward references outside of function annotations #1004
Comments
Thanks for the report - I'll need to poke around a bit to decide on the best fix, but this is a great bug report |
FWIW, I'd guess that wrapping |
Yes, probably a couple of
(Side comment: I wonder why type annotations use strings for recursive types or forward references, instead of thunks / lambdas). Related question: I was originally going to jump into stateful testing to try out trees, but got confused by some things in the examples described, so I'll ask here. Feel free to remove / move if appropriate:
Thanks for sharing a great library. |
I'll leave the others, but this is because type annotations are meant to work for static analysis and thus can't require evaluating code. |
We actually have two problems here:
|
@Zac-HD based on #1026 (comment), is this actually closed? It seems like the fix doesn't support NamedTuple (though based on discussion it seems like we might not be able to) |
Unfortunately there is no way to resolve forward references in Python 3.6, if they are not function annotations. The example above should now fail with an explicit |
@Zac-HD In which case I think I'll reopen the issue. Even if we can't/won't fix this any time soon I think it's a legitimate thing to want supported. Hopefully in future it will become easier to do so (or maybe we'll figure out some clever trick). |
Fair enough! I consider that a feature request though, which might be possible on Python 3.7 😄 (retagged, retitled, unassigned myself) |
Deferred annotations make this slightly less annoying, because an official way to resolve forward references has now been published: https://www.python.org/dev/peps/pep-0563/#resolving-type-hints-at-runtime What to do when this fails at runtime - and especially how to make the error message useful - is left as an exercise for the implementer. |
The sample code:
(Part of) the stack trace:
The text was updated successfully, but these errors were encountered: