You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Current specification is not clear about how async functions returning TypeIs or TypeGuards should be treated, but I believe this would be useful for async lazy evaluation of typestate fields, example:
fromtyping_extensionsimportTypeIs, TypeVar, GenericT=TypeVar('T', int|None, int, None, covariant=True)
classA(Generic[T]):
_a: Tasyncdefget_a(self: A[int|None]) ->int|None:
a=123# imagine some expensive async operation, e.g. fetch value from APIself._a=areturnself._adefmethod_requires_a(self: A[int]) ->None:
raiseNotImplementedErrordef__init__(self):
self._a=Noneasyncdefhas_a(a: A[int|None]) ->TypeIs[A[int]]:
returnawaita.get_a() isnotNoneasyncdefmain(a: A[int|None]):
ifawaithas_a(a):
a.method_requires_a() # currently fails as type was not narrowed
The text was updated successfully, but these errors were encountered:
hello sir I am trying a compatible function which could solve this issue could you please describe me more about the issue or where do you need changes exactly
RSzipper
added a commit
to RSzipper/typing
that referenced
this issue
Feb 19, 2025
Currently it seems impossible to have async
TypeGuard
orTypeIs
:Current specification is not clear about how async functions returning
TypeIs
orTypeGuards
should be treated, but I believe this would be useful for async lazy evaluation of typestate fields, example:The text was updated successfully, but these errors were encountered: