Add PEP 593 (Annotated etc.) typing_extensions stubs#3369
Add PEP 593 (Annotated etc.) typing_extensions stubs#3369JelleZijlstra merged 2 commits intopython:masterfrom
Conversation
The code has been added to typing_extensions in python/typing#632 and python/typing#639. I really didn't know how to type Annotated and _AnnotatedAlias here – feel free to correct this.
ilevkivskyi
left a comment
There was a problem hiding this comment.
Thanks! Looks good, just one comment.
| ) -> Dict[str, Any]: ... | ||
|
|
||
| Annotated: _SpecialForm = ... | ||
| _AnnotatedAlias: Any = ... |
There was a problem hiding this comment.
This is a private thing and doesn't really need to be here. If you actually need it for something, then please add an # undocumented comment.
There was a problem hiding this comment.
You're right – let me explain why I added it, there should be a better way to achieve what I need: I have some code that needs to check if an object is an instance of Annotated. What I have right now:
from typing_extensions import _AnnotatedAlias, Annotated
def fun(x):
if isinstance(x, _AnnotatedAlias):
# ...
else:
# ...
fun(int)
fun(Annotated[int, 'whatever'])get_origin introduced in typing in Python 3.8 could help here but it's not modified to know about Annotated yet. I'm happy to remove _AnnotatedAlias from the stub and silence mypy error though if we don't want to pollute stubs with unwanted things.
There was a problem hiding this comment.
I think it is fine if you add # undocumented here, see https://github.com/python/typeshed/blob/master/CONTRIBUTING.md#what-to-include
The code has been added to typing_extensions in
python/typing#632 and
python/typing#639.
I really didn't know how to type Annotated and _AnnotatedAlias here –
feel free to correct this.