Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions mypy/newsemanal/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -2858,11 +2858,9 @@ def visit_decorator(self, dec: Decorator) -> None:
self.fail("@final cannot be used with non-method functions", d)
for i in reversed(removed):
del dec.decorators[i]
if not dec.is_overload or dec.var.is_property:
if self.type:
dec.var.info = self.type
dec.var.is_initialized_in_class = True
self.add_symbol(dec.var.name(), dec, dec)
if (not dec.is_overload or dec.var.is_property) and self.type:
dec.var.info = self.type
dec.var.is_initialized_in_class = True
if not no_type_check and self.recurse_into_functions:
dec.func.accept(self)
if dec.decorators and dec.var.is_property:
Expand Down
21 changes: 21 additions & 0 deletions test-data/unit/check-newsemanal.test
Original file line number Diff line number Diff line change
Expand Up @@ -1054,3 +1054,24 @@ class Test:
import a
def __init__(self) -> None:
some_module = self.a

[case testNewAnalyzerProperty]
class A:
@property
def x(self) -> B:
return 0 # E: Incompatible return value type (got "int", expected "B")

@property
def y(self) -> B:
pass

@y.setter
def y(self, x: B) -> None:
pass

class B: pass

a = A()
reveal_type(a.x) # E: Revealed type is '__main__.B'
a.y = 1 # E: Incompatible types in assignment (expression has type "int", variable has type "B")
[builtins fixtures/property.pyi]
1 change: 0 additions & 1 deletion test-data/unit/pythoneval.test
Original file line number Diff line number Diff line change
Expand Up @@ -1368,5 +1368,4 @@ reveal_type(x['test'][0])
typing.pyi:251: error: Class typing.Sequence has abstract attributes "__len__"
typing.pyi:251: note: If it is meant to be abstract, add 'abc.ABCMeta' as an explicit metaclass
ast.pyi:31: error: Name 'PyCF_ONLY_AST' already defined (possibly by an import)
builtins.pyi:39: error: Name '__class__' already defined on line 39
_testNewAnalyzerBasicTypeshed_newsemanal.py:4: error: Revealed type is 'builtins.int*'