Skip to content

Commit 243ae66

Browse files
committed
Don't enforce @AbstractMethod and @coroutine consistency on properties.
See python/typeshed#6361. PiperOrigin-RevId: 412119101
1 parent e3dcd51 commit 243ae66

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

pytype/pyi/parser_test.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2026,6 +2026,21 @@ def name(self) -> str: ...
20262026
def name(self) -> int: ...
20272027
""", 1, "Invalid property decorators for method `name`")
20282028

2029+
def test_abstract_property(self):
2030+
self.check("""
2031+
class Foo:
2032+
@property
2033+
@abstractmethod
2034+
def x(self) -> int: ...
2035+
@x.setter
2036+
def x(self, y: int) -> None: ...
2037+
""", """
2038+
from typing import Annotated
2039+
2040+
class Foo:
2041+
x: Annotated[int, 'property']
2042+
""")
2043+
20292044

20302045
class MergeSignaturesTest(parser_test_base.ParserTestBase):
20312046

pytype/pytd/codegen/function.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
"""Function definitions in pyi files."""
22

33
import collections
4+
import dataclasses
45

56
from typing import Any, Dict, Iterable, List, Optional, Tuple
67

7-
import dataclasses
8-
98
from pytype.pytd import pytd
109

1110

@@ -226,6 +225,10 @@ def add_overload(self, fn: NameAndSig):
226225
# For properties, we can have at most one of setter, getter and deleter,
227226
# and no other overloads
228227
self.add_property(fn.decorator, fn.signature)
228+
# For properties, it's fine if, e.g., the getter is abstract but the
229+
# setter is not, so we skip the @abstractmethod and @coroutine
230+
# consistency checks.
231+
return
229232
elif self.decorator == fn.decorator:
230233
# For other decorators, we can have multiple overloads but they need to
231234
# all have the same decorator

0 commit comments

Comments
 (0)