Skip to content

Convert typing declarations to use TypeAlias #345

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

Closed
Dr-Irv opened this issue Sep 30, 2022 · 5 comments · Fixed by #349
Closed

Convert typing declarations to use TypeAlias #345

Dr-Irv opened this issue Sep 30, 2022 · 5 comments · Fixed by #349

Comments

@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Sep 30, 2022

See discussion here: #341 (comment)

Should we change _typing.pyi to make all these types that we create be declared with TypeAlias (imported from typing_extensions) ?

@twoertwein - your opinion?

@AlexWaygood
Copy link

AlexWaygood commented Sep 30, 2022

Fun fact: typeshed pretends that typing_extensions is part of the standard library, meaning that all type checkers also believe that typing_extensions is part of the standard library. This means that (since this is a stubs-only project, and will never be executed at runtime) you should be able to use types from typing_extensions (and also _typeshed, which we treat similarly) without adding a dependency on typing_extensions :)

@twoertwein
Copy link
Member

Should we change _typing.pyi to make all these types that we create be declared with TypeAlias (imported from typing_extensions) ?

I think flake8-pyi recommends that and checks for it (disable in our config for now). Definitely good to make it more explicit.

@twoertwein
Copy link
Member

This means that (since this is a stubs-only project, and will never be executed at runtime) you should be able to use types from typing_extensions (and also _typeshed, which we treat similarly) without adding a dependency on typing_extensions :)

Could also start using _typeshed.Self in the stubs (Y019) @Dr-Irv

@Dr-Irv
Copy link
Collaborator Author

Dr-Irv commented Oct 2, 2022

Could also start using _typeshed.Self in the stubs (Y019)

Or from typing_extensions, since Self is part of python 3.11

https://docs.python.org/3.11/library/typing.html#typing.Self

@AlexWaygood
Copy link

Could also start using _typeshed.Self in the stubs (Y019)

Or from typing_extensions, since Self is part of python 3.11

https://docs.python.org/3.11/library/typing.html#typing.Self

typing_extensions.Self is unfortunately not yet supported by mypy or pytype (pyright supports it, not sure about pyre). But _typeshed.Self is just a common-or-garden TypeVar with a special name (Self = TypeVar("Self")), so it works fine with all type checkers.

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 a pull request may close this issue.

3 participants