Skip to content

properties appear to lose their specialness inside context managers at class scope #15507

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

Open
glyph opened this issue Jun 23, 2023 · 0 comments
Labels
bug mypy got something wrong topic-descriptors Properties, class vs. instance attributes

Comments

@glyph
Copy link

glyph commented Jun 23, 2023

Bug Report

Although reveal_type claims that @property objects are simply callables of the type of function they decorate, mypy does know that they have setter and getter attributes. However, if they are used inside a contextmanager, they lose this special property (although it obviously remains so at runtime):

To Reproduce

from contextlib import contextmanager
from typing import Iterator

@contextmanager
def noop() -> Iterator[None]:
    yield

class X:
    @property
    def a(self) -> int:
        return 7

    with noop():
        @a.setter
        def a(self, newValue: int) -> None:
            print("was set", newValue)


X().a = 9

https://mypy-play.net/?mypy=latest&python=3.11&gist=31b6919b60f665c999edc543233c3484

Expected Behavior

I'd expect neither of the errors here.

Actual Behavior

main.py:14: error: "Callable[[X], int]" has no attribute "setter"  [attr-defined]
main.py:19: error: Property "a" defined in "X" is read-only  [misc]
Found 2 errors in 1 file (checked 1 source file)
@glyph glyph added the bug mypy got something wrong label Jun 23, 2023
@AlexWaygood AlexWaygood added the topic-descriptors Properties, class vs. instance attributes label Jun 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-descriptors Properties, class vs. instance attributes
Projects
None yet
Development

No branches or pull requests

2 participants