Skip to content

Add PEP 593 (Annotated etc.) typing_extensions stubs#3369

Merged
JelleZijlstra merged 2 commits intopython:masterfrom
jstasiak:annotated
Oct 16, 2019
Merged

Add PEP 593 (Annotated etc.) typing_extensions stubs#3369
JelleZijlstra merged 2 commits intopython:masterfrom
jstasiak:annotated

Conversation

@jstasiak
Copy link
Contributor

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.

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.
Copy link
Member

@ilevkivskyi ilevkivskyi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Looks good, just one comment.

) -> Dict[str, Any]: ...

Annotated: _SpecialForm = ...
_AnnotatedAlias: Any = ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is fine if you add # undocumented here, see https://github.com/python/typeshed/blob/master/CONTRIBUTING.md#what-to-include

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All right, done!

@JelleZijlstra JelleZijlstra merged commit 6e4f640 into python:master Oct 16, 2019
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

Successfully merging this pull request may close these issues.

3 participants