Skip to content

Support cached_property #1446

@graipher

Description

@graipher

Summary

Currently the type of a functools.cached_property is Unknown, as the standardlibrary functools does not have type annotations.

from functools import cached_property
from typing import reveal_type


class Foo:
    @cached_property
    def foo(self) -> str:
        return "This is expensive"


reveal_type(Foo().foo)

Output:

info[revealed-type]: Revealed type
  --> main.py:11:11
   |
11 | reveal_type(Foo().foo)
   |             ^^^^^^^^^ `Unknown`
   |

Expected:
Some variant of bound method Foo.foo() -> str, which is what ty reveals without the decorator.

Playground link

Is this an issue with typeshed?

Version

ty 0.0.1-alpha.24

Metadata

Metadata

Assignees

No one assigned

    Labels

    genericsBugs or features relating to ty's generics implementation

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions