Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mypy doesn't object to property methods that don't exist #18327

Open
tungol opened this issue Dec 22, 2024 · 0 comments
Open

Mypy doesn't object to property methods that don't exist #18327

tungol opened this issue Dec 22, 2024 · 0 comments
Labels
bug mypy got something wrong

Comments

@tungol
Copy link
Contributor

tungol commented Dec 22, 2024

Bug Report

Mypy includes functools.cached_property on it's list of property-list types, but considers it to be too identical to property. It allows the use of cached_property.setter and cached_property.deleter without raising an error, despite the fact that neither of these are methods that exist on cached_property.

I discovered this while looking at permutations of property-like behavior for python/typeshed#13276.

Actually, I realized just now that it can be anything from any of the property types. See the second playground link.

To Reproduce

Playground link showing : https://mypy-play.net/?mypy=latest&python=3.12&gist=f5336c7a8df8f028a565bab576b74062

This one shows that mypy doesn't object to non-existent methods of property used as a decorator:

https://mypy-play.net/?mypy=latest&python=3.12&gist=d91764177a604ba5640a1fe741718f52

class PropertyTest1:
    _value: int | None = None

    @property
    def foo(self) -> int | None:
        return self._value

    @foo.whatever  # No error here
    def foo(self, value: int) -> None:
        self._value = value

Expected Behavior

I expect mypy to generate errors for methods that don't exist in the stubs, even with the special-cased behavior.

Actual Behavior

No errors are generated.

@tungol tungol added the bug mypy got something wrong label Dec 22, 2024
@tungol tungol changed the title Mypy doesn't object to doing things with cached_property that don't work Mypy doesn't object to property methods that don't exist Dec 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

1 participant