Skip to content

Commit

Permalink
stubgen: fix missing property setter in semantic analysis mode
Browse files Browse the repository at this point in the history
The semantic analyzer treats properties as overloaded functions.
This was previously ignored by stubgen but regressed in python#15232.

Fixes python#16300
  • Loading branch information
hamdanal committed Oct 21, 2023
1 parent ff8cebb commit 2c0748d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions mypy/stubgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,7 @@ def process_decorator(self, o: Decorator) -> None:
Only preserve certain special decorators such as @abstractmethod.
"""
o.func.is_overload = False
for decorator in o.original_decorators:
if not isinstance(decorator, (NameExpr, MemberExpr)):
continue
Expand Down
2 changes: 0 additions & 2 deletions mypy/stubutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,8 +669,6 @@ def set_defined_names(self, defined_names: set[str]) -> None:
self.add_name(f"{pkg}.{t}", require=False)

def check_undefined_names(self) -> None:
print(self._all_)
print(self._toplevel_names)
undefined_names = [name for name in self._all_ or [] if name not in self._toplevel_names]
if undefined_names:
if self._output:
Expand Down
18 changes: 18 additions & 0 deletions test-data/unit/stubgen.test
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,24 @@ class A:
def f(self, x) -> None: ...
def h(self) -> None: ...

[case testProperty_semanal]
class A:
@property
def f(self):
return 1
@f.setter
def f(self, x): ...

def h(self):
self.f = 1
[out]
class A:
@property
def f(self): ...
@f.setter
def f(self, x) -> None: ...
def h(self) -> None: ...

-- a read/write property is treated the same as an attribute
[case testProperty_inspect]
class A:
Expand Down

0 comments on commit 2c0748d

Please sign in to comment.