Skip to content
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

mypy native support for assert_type #5

Closed
Rogdham opened this issue Aug 20, 2022 · 2 comments
Closed

mypy native support for assert_type #5

Rogdham opened this issue Aug 20, 2022 · 2 comments

Comments

@Rogdham
Copy link

Rogdham commented Aug 20, 2022

Hello,

It seems that mypy now has support for assert_type (related PR).

Btw, assert_type will be in stdlib starting from Python 3.11 (although not doing anything by itself).

So I'm curious: does your library provide any added features, or was it just a temporary way to have an assert_type function until the implementation in mypy?

@thejcannon
Copy link
Owner

The latter, for sure "temporary way to have an assert_type function until the implementation in mypy"

I had some code which was very complex in terms of generic typing and needed a way to make sure changes to the codebase didn't change the resulting typing, and at the time mypy didn't support it (and I couldn't use the other type-checking libraries).

I'll be very happy to archive this library/repo when assert_type is something I'll be able to use in my code 😅

@Rogdham
Copy link
Author

Rogdham commented Aug 22, 2022

Alright, noted, thank you for the answer!

Right now, something like the following can be used:

if TYPE_CHECKING:
    from typing_extensions import assert_type
else:
    def assert_type(val, _):
        return val

@Rogdham Rogdham closed this as completed Aug 22, 2022
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

No branches or pull requests

2 participants