Skip to content

Commit 27c4b46

Browse files
authored
stubgen: fix missing property setter in semantic analysis mode (#16303)
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
1 parent a3af87b commit 27c4b46

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

mypy/stubgen.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,7 @@ def process_decorator(self, o: Decorator) -> None:
633633
634634
Only preserve certain special decorators such as @abstractmethod.
635635
"""
636+
o.func.is_overload = False
636637
for decorator in o.original_decorators:
637638
if not isinstance(decorator, (NameExpr, MemberExpr)):
638639
continue

mypy/stubutil.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -669,8 +669,6 @@ def set_defined_names(self, defined_names: set[str]) -> None:
669669
self.add_name(f"{pkg}.{t}", require=False)
670670

671671
def check_undefined_names(self) -> None:
672-
print(self._all_)
673-
print(self._toplevel_names)
674672
undefined_names = [name for name in self._all_ or [] if name not in self._toplevel_names]
675673
if undefined_names:
676674
if self._output:

test-data/unit/stubgen.test

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,24 @@ class A:
377377
def f(self, x) -> None: ...
378378
def h(self) -> None: ...
379379

380+
[case testProperty_semanal]
381+
class A:
382+
@property
383+
def f(self):
384+
return 1
385+
@f.setter
386+
def f(self, x): ...
387+
388+
def h(self):
389+
self.f = 1
390+
[out]
391+
class A:
392+
@property
393+
def f(self): ...
394+
@f.setter
395+
def f(self, x) -> None: ...
396+
def h(self) -> None: ...
397+
380398
-- a read/write property is treated the same as an attribute
381399
[case testProperty_inspect]
382400
class A:

0 commit comments

Comments
 (0)