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

Stubgen *.pyi not generated with "setter" #16300

Closed
anngokul opened this issue Oct 20, 2023 · 1 comment · Fixed by #16303
Closed

Stubgen *.pyi not generated with "setter" #16300

anngokul opened this issue Oct 20, 2023 · 1 comment · Fixed by #16303
Labels
bug mypy got something wrong topic-stubgen

Comments

@anngokul
Copy link

I am having some class like

class MyClass:
    _proprty_a: int
    
    def __init__(self, a: int):
        self._proprty_a = a
    
    @property
    def property_a(self) -> int:
        return self._proprty_a

    @property_a.setter
    def property_a(self, property_a: int) -> None:
        self._proprty_a = property_a

On creating the stubgen pyi file, the setter is not available.

If the implementing python code is having the

my_class = MyClass(10)
my_class.property_a = 19

Then mypy gives error as the property is read-only.
error: Property "property_a " defined in "MyClass" is read-only [misc]

Expected Behavior
Expected to have the setter in *.pyi

Actual Behavior

On Creating stubgen for this, got the *.pyi with the following content

class MyClass:
    def __init__(self, a: int) -> None: ...
    @property
    def property_a(self) -> int: ...

Your Environment

  • Mypy version used: mypy 1.6.1 (compiled: yes)
  • Python version used: 3.10.8
@anngokul anngokul added the bug mypy got something wrong label Oct 20, 2023
@anngokul anngokul changed the title Stubgen *.pyi not generated with "setters" Stubgen *.pyi not generated with "setter" Oct 20, 2023
@hamdanal
Copy link
Collaborator

I just had the same issue.
This appears to be a regression in version 1.4 probably caused by #15232. I'll investigate and send a fix.

hamdanal added a commit to hamdanal/mypy that referenced this issue Oct 21, 2023
The semantic analyzer treats properties as overloaded functions.
This was previously ignored by stubgen but regressed in python#15232.

Fixes python#16300
JelleZijlstra pushed a commit that referenced this issue Oct 21, 2023
The semantic analyzer treats properties as overloaded functions. This
was previously ignored by stubgen but regressed in #15232.
This PR restores the original behavior.

Fixes #16300
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-stubgen
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants