Skip to content

Pyright has problem with combo of @property and @cache #2133

@MapleCCC

Description

@MapleCCC

Describe the bug
The combo use of @property and @cache is backed by the document of functools.cached_property, so it should be considered a valid use case. However, pyright seems to have some bugs in handling such case.

To Reproduce

from functools import cache

class Rectangle:
    def __init__(self, length: int, width: int) -> None:
        self._length = length
        self._width = width

    @property
    @cache
    def area(self) -> int:
        return self._length * self._width

def is_large_rectangle(rec: Rectangle) -> bool:
    return rec.area >= 100

rec = Rectangle(10, 10)
print(is_large_rectangle(rec))

Pyright complains that Operator ">=" not supported for types "_lru_cache_wrapper[int]" and "Literal[100]".

Expected behavior
There should be no error for the above code.

VS Code extension or command-line
Pyright command-line tool 1.1.158

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions