From 27c4b462aa4cf269397253eca7a88e7fbbf4e43e Mon Sep 17 00:00:00 2001 From: Ali Hamdan Date: Sat, 21 Oct 2023 22:25:20 +0200 Subject: [PATCH] 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 --- mypy/stubgen.py | 1 + mypy/stubutil.py | 2 -- test-data/unit/stubgen.test | 18 ++++++++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/mypy/stubgen.py b/mypy/stubgen.py index 395a49fa4e08..a2f07a35eaa2 100755 --- a/mypy/stubgen.py +++ b/mypy/stubgen.py @@ -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 diff --git a/mypy/stubutil.py b/mypy/stubutil.py index 22e525c14e7c..cc3b63098fd2 100644 --- a/mypy/stubutil.py +++ b/mypy/stubutil.py @@ -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: diff --git a/test-data/unit/stubgen.test b/test-data/unit/stubgen.test index d83d74306230..64a1353b29b3 100644 --- a/test-data/unit/stubgen.test +++ b/test-data/unit/stubgen.test @@ -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: