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
For context - I've tried asking the same question on typing Gitter and had no luck there since I believe the visibility is quite low and I got no comments to the message up to now.
I've checked the issues 1, 2
I am taking my luck here just to understand if what I'm trying to achieve is possible at all or if I shouldn't bother trying.
The idea seems simple - we need to preserve all types of a function the decorator with arguments is being applied to. However, the issue comes when the decorator is supposed to work with both sync and async functions.
The solution I've come close with is the following:
However, TypeGuard doesn't narrow down the type thus mypy throws an error on return_value: str = test(): Incompatible types in assignment (expression has type "Awaitable[str] | str", variable has type "str") [assignment]
The other try was through @typing.overload but it seems it doesn't work in this case since overloading happens inside the my_dec.
I would appreciate any help, directions and resources I could look into to solve this.
The text was updated successfully, but these errors were encountered:
Hey there!
For context - I've tried asking the same question on typing Gitter and had no luck there since I believe the visibility is quite low and I got no comments to the message up to now.
I've checked the issues 1, 2
I am taking my luck here just to understand if what I'm trying to achieve is possible at all or if I shouldn't bother trying.
The idea seems simple - we need to preserve all types of a function the decorator with arguments is being applied to. However, the issue comes when the decorator is supposed to work with both sync and async functions.
The solution I've come close with is the following:
However,
TypeGuard
doesn't narrow down the type thus mypy throws an error onreturn_value: str = test()
:Incompatible types in assignment (expression has type "Awaitable[str] | str", variable has type "str") [assignment]
The other try was through
@typing.overload
but it seems it doesn't work in this case since overloading happens inside themy_dec
.I would appreciate any help, directions and resources I could look into to solve this.
The text was updated successfully, but these errors were encountered: