-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Add support for typing_extensions.Annotated #7021
Comments
If nobody else is working on this, I'd be happy to do it. |
OK, go ahead and try it! |
Doing this right turned out to be significantly more difficult than I anticipated. It's trivial to blindly strip away annotations when encountered, or to support anything that can be put in a If we're okay with just relying on plugins to handle any fancy business, then dropping all annotations and resolving to the inner type, I can still do that fairly easily. But I'm not quite sure what the vision is here going forward. |
For a first pass, I think it is totally fine to just discard the additional annotations. The important bit is that we are able to process code with In order to support actually using |
Okay, thanks for the clarification. It looks like plugins will be able to use I'll have something up this week for review, hopefully. |
Yeah, this seems pretty reasonable to me. The only caveat is that we currently do a bit of hackery in the earlier parsing and semantic analysis layers to handle some str/unicode/bytes nonsense when constructing RawExpressionTypes. I'm not sure how complicated pushing this logic up into type analysis will be -- probably it won't be too bad? But if it gets too annoying, we could maybe sidestep the issue by having RawExpressionType contain a union of Expression and the existing allowed values. That would let us leave most of the existing hackery alone, just at the cost of introducing even more hackery. ¯\_(ツ)_/¯ The only other main constraint is that we need to make sure RawExpressionTypes don't leak out of the semantic analysis/type analysis phase -- but the strategy of delegating everything to plugins and/or dropping all annotations ought to handle that. |
Closes #7021. This adds basic support for `typing_extensions.Annotated`. Currently, we just discard all annotations and resolve to the inner type. Plugins can use `get_type_analyze_hook` to try to intervene before this step, but most of the arguments that aren't just names or `Literal`-able values will have already been mangled by this point. Nothing other than the type sees any sort of validation, either. See the issue discussion for more on this.
I am not able to find a single usage example of PEP 593 struct2. Could someone share one please? I am using python 3.11. |
It would be great to support
Annotated
types as specified by PEP 593. This should be pretty easy to implement.The text was updated successfully, but these errors were encountered: