From 75b68fa2c0d32bd08b98b00aece20c22d82b1b15 Mon Sep 17 00:00:00 2001 From: Ali Hamdan Date: Sun, 14 Jan 2024 18:19:12 +0100 Subject: [PATCH] stubgen: Do not ignore property deleter (#16781) Fixes #16690 --- mypy/stubgen.py | 2 +- test-data/unit/stubgen.test | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/mypy/stubgen.py b/mypy/stubgen.py index e753fd1e73d5..1f7a01e6ae3c 100755 --- a/mypy/stubgen.py +++ b/mypy/stubgen.py @@ -685,7 +685,7 @@ def process_decorator(self, o: Decorator) -> None: elif fullname in OVERLOAD_NAMES: self.add_decorator(qualname, require_name=True) o.func.is_overload = True - elif qualname.endswith(".setter"): + elif qualname.endswith((".setter", ".deleter")): self.add_decorator(qualname, require_name=False) def get_fullname(self, expr: Expression) -> str: diff --git a/test-data/unit/stubgen.test b/test-data/unit/stubgen.test index 50437c903530..751a1a7fbbcf 100644 --- a/test-data/unit/stubgen.test +++ b/test-data/unit/stubgen.test @@ -368,6 +368,8 @@ class A: return 1 @f.setter def f(self, x): ... + @f.deleter + def f(self): ... def h(self): self.f = 1 @@ -377,6 +379,8 @@ class A: def f(self): ... @f.setter def f(self, x) -> None: ... + @f.deleter + def f(self) -> None: ... def h(self) -> None: ... [case testProperty_semanal] @@ -386,6 +390,8 @@ class A: return 1 @f.setter def f(self, x): ... + @f.deleter + def f(self): ... def h(self): self.f = 1 @@ -395,6 +401,8 @@ class A: def f(self): ... @f.setter def f(self, x) -> None: ... + @f.deleter + def f(self) -> None: ... def h(self) -> None: ... -- a read/write property is treated the same as an attribute @@ -2338,10 +2346,12 @@ class B: @property def x(self): return 'x' - @x.setter def x(self, value): self.y = 'y' + @x.deleter + def x(self): + del self.y [out] class A: @@ -2355,6 +2365,8 @@ class B: y: str @x.setter def x(self, value) -> None: ... + @x.deleter + def x(self) -> None: ... [case testMisplacedTypeComment] def f():