Skip to content

Commit 82849bd

Browse files
committed
support propertied decorators
1 parent eb1b1e0 commit 82849bd

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

mypy/semanal.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1047,6 +1047,7 @@ def visit_decorator(self, dec: Decorator) -> None:
10471047
d.accept(self)
10481048
removed: List[int] = []
10491049
no_type_check = False
1050+
could_be_decorated_property = False
10501051
for i, d in enumerate(dec.decorators):
10511052
# A bunch of decorators are special cased here.
10521053
if refers_to_fullname(d, 'abc.abstractmethod'):
@@ -1094,14 +1095,16 @@ def visit_decorator(self, dec: Decorator) -> None:
10941095
removed.append(i)
10951096
else:
10961097
self.fail("@final cannot be used with non-method functions", d)
1098+
elif not dec.var.is_property:
1099+
could_be_decorated_property = True
10971100
for i in reversed(removed):
10981101
del dec.decorators[i]
10991102
if (not dec.is_overload or dec.var.is_property) and self.type:
11001103
dec.var.info = self.type
11011104
dec.var.is_initialized_in_class = True
11021105
if not no_type_check and self.recurse_into_functions:
11031106
dec.func.accept(self)
1104-
if dec.decorators and dec.var.is_property:
1107+
if could_be_decorated_property and dec.decorators and dec.var.is_property:
11051108
self.fail('Decorated property not supported', dec)
11061109
if dec.func.is_abstract and dec.func.is_final:
11071110
self.fail(f"Method {dec.func.name} is both abstract and final", dec)

test-data/unit/semanal-errors.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,7 +1231,7 @@ from typing import overload
12311231
class A:
12321232
@overload # E: An overloaded function outside a stub file must have an implementation
12331233
def f(self) -> int: pass
1234-
@property # E: Decorated property not supported
1234+
@property
12351235
@overload
12361236
def f(self) -> int: pass
12371237
[builtins fixtures/property.pyi]
@@ -1244,7 +1244,7 @@ class A:
12441244
@dec # E: Decorated property not supported
12451245
@property
12461246
def f(self) -> int: pass
1247-
@property # E: Decorated property not supported
1247+
@property
12481248
@dec
12491249
def g(self) -> int: pass
12501250
[builtins fixtures/property.pyi]

0 commit comments

Comments
 (0)