Last active
July 26, 2024 15:38
-
-
Save CodeByAidan/1770443d22e72ed34d2c80f5305beb95 to your computer and use it in GitHub Desktop.
will be updating this a lot whenever I want to use typing but with typing that's not present in typing library.
mypy + pylance ready!
![:trollface: :trollface:](https://github.githubassets.com/images/icons/emoji/trollface.png)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import annotations | |
from typing import Any, TypeVar, overload | |
T = TypeVar("T") | |
@overload | |
def cast(typ: type[T], val: Any, /) -> T: ... | |
@overload | |
def cast(typ: str, val: Any, /) -> Any: ... | |
@overload | |
def cast(typ: object, val: Any, /) -> Any: ... | |
def cast(typ: Any, val: Any, /) -> Any: # fmt: off | |
"""Cast a value to a type. | |
This returns the value unchanged. To the type checker this | |
signals that the return value has the designated type, but at | |
runtime we intentionally don't check anything (we want this | |
to be as fast as possible). | |
""" | |
return val | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment