Skip to content

Can't call function on object that is also a method #821

@ndmitchell

Description

@ndmitchell

Describe the Bug

from typing import *

P = ParamSpec("P")
RV = TypeVar("RV", covariant=True)

class CachedMethod(Protocol, Generic[P, RV]):
    @staticmethod
    def clear_cache(cache: Any) -> None: ...

    def __call__(self, *args: P.args, **kwargs: P.kwargs) -> RV: ...

def cache_on_self(fn: Callable[Concatenate[Any, P], RV]) -> CachedMethod[P, RV]:
    ...

class Foo:
    @cache_on_self
    def pointwise_read_writes(self): ...

    def f(self):
        self.pointwise_read_writes.clear_cache(self) # E: ERROR 20:9-47: Object of class `MethodType` has no attribute `clear_cache`

This should work as pointwise_read_writes is actually a CachedMethod.

Sandbox Link

https://pyrefly.org/sandbox/?code=GYJw9gtgBALgngBwJYDsDmUkQWEMoBUAUEQApQC8UpAhiDRAMoICmAxgBQBEpXAlEQBKANUpQAKohbC63EVwA0UNmABudJDRQwK4kAFcWAomwA2NAM4WoAYRpsAFiwAmAWRYwHYZx1LgYYCqmSgDiLCgsIEhsANqkSiIAunwAXERQGVAAAhYwNDDREB5ezumZzizAyqYsdAD6bPZOHI2OLClQAIIocHxQALQAfFAAcmARHQB00ySZUBVVdQ00pqZLHBYspsBKBHRoFh2kk-sWuwQA1gDup0eT16d9Q1AiUzNEC8pNLHXjdZvbDjAFAdOyrGgAIxqMRs40aMHC+RYMW6cCUpESCWEyQGwzsbTcxW8cSxiTSc2mkxIZks1gAYmAwOTMllWk5fih-ltgGUMp8cKgYFckJs6iBas46lcogiLBtuakoJTZuVKlBgPLtqleXMoADgJMBdphaLxTRJdKkLLJmZaiBlm1NcABEA

(Only applicable for extension issues) IDE Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    UserBugs reported by external users that should be prioritisedpytorch

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions