Skip to content

mypy native support for assert_type #5

Closed

Description

@Rogdham

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?

Activity

  1. thejcannon commented on Aug 22, 2022

    @thejcannon
    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 😅

  2. Rogdham commented on Aug 22, 2022

    @Rogdham
    Author

    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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions