-
Hello! I am trying to define an annotated proxy class. Previously, the type checker did not approve all my run-time compatible tries. But recently, I found the following usage will satisfy my requirement without raising a type checker error: from typing import TypeVar, Sequence
from typing_extensions import TypeAliasType, reveal_type
T = TypeVar("T")
proxy = TypeAliasType("proxy", T, type_params=(T,))
# No errors are raised, and I am happy to see that!
def test_func(val1: Sequence[proxy[int]], val2: Sequence[proxy[str]]) -> Sequence[str]:
return val2
reveal_type(test_func) # (val1: Sequence[int], val2: Sequence[str]) -> Sequence[str] How However, the usage of VS Code extension or command-line
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 8 replies
-
Yes, this should work fine. In fact, you shouldn't need to use proxy: TypeAlias = T |
Beta Was this translation helpful? Give feedback.
Yes, this should work fine. In fact, you shouldn't need to use
typing.TypeAliasType
. The older-styletyping.TypeAlias
should work fine here. There's currently a bug in pyright whereproxy: TypeAlias = T
does not work correctly. I'll fix this for the next release.