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
Describe the bug
I declare a generic return type, and I have a provider of that same return type, but cached. Mypy does not declare an error but Pyright raises one. If I remove the caching no error is reported.
I raised this issue in pyright's repo. @erictraut stated that cache method does not maintain the signature of the function it's decorating. This other issue might be related.
Code
from abc import abstractmethod
from functools import cache
from typing import Any, Generic, Protocol, TypeVar
from typing_extensions import NamedTuple
T = TypeVar("T")
T_co = TypeVar("T_co", covariant=True)
class ServiceId(NamedTuple, Generic[T]):
id: str
class Provider(Protocol[T_co]):
@abstractmethod
def __call__(self) -> T_co:
...
class Servicer:
_d: dict[str, Any]
@cache # commenting this line removes the error
def get_service(self, service_id: ServiceId[T]) -> T:
return self._d[service_id.id]
def get_provider(self, service_id: ServiceId[T]) -> Provider[T]:
return lambda: self.get_service(service_id) # Expression of type "() -> T@get_service" cannot be assigned to return type "Provider[T@get_provider]"
The text was updated successfully, but these errors were encountered:
Describe the bug
I declare a generic return type, and I have a provider of that same return type, but cached. Mypy does not declare an error but Pyright raises one. If I remove the caching no error is reported.
I raised this issue in pyright's repo. @erictraut stated that
cache
method does not maintain the signature of the function it's decorating. This other issue might be related.Code
The text was updated successfully, but these errors were encountered: