Skip to content

fix crash when serializing a type-ignored property setter #3493

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 3, 2017
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
3 changes: 2 additions & 1 deletion mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,9 +564,10 @@ def analyze_property_with_multi_part_definition(self, defn: OverloadedFuncDef) -
first_item.var.is_settable_property = True
# Get abstractness from the original definition.
item.func.is_abstract = first_item.func.is_abstract
item.func.accept(self)
else:
self.fail("Decorated property not supported", item)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should also be fixed (it's in a sense the true reason for the issue). But not in this PR.

if isinstance(item, Decorator):
item.func.accept(self)

def analyze_function(self, defn: FuncItem) -> None:
is_method = self.is_class_scope()
Expand Down
29 changes: 29 additions & 0 deletions test-data/unit/check-incremental.test
Original file line number Diff line number Diff line change
Expand Up @@ -2684,3 +2684,32 @@ b.x.y
[out3]
tmp/c.py:2: error: Revealed type is '<stale cache: consider running mypy without --quick>'
tmp/c.py:5: error: "<stale cache: consider running mypy without --quick>" has no attribute "y"

[case testSerializeAbstractPropertyIncremental]
from abc import abstractmethod
import typing
class A:
@property
def f(self) -> int:
return 1
@f.setter # type: ignore
@abstractmethod
def f(self, x: int) -> None:
pass
a = A()
[builtins fixtures/property.pyi]

[case testSerializeAbstractPropertyDisallowUntypedIncremental]
# flags: --disallow-untyped-defs
from abc import abstractmethod
import typing
class A:
@property
def f(self) -> int:
return 1
@f.setter # type: ignore
@abstractmethod
def f(self, x: int) -> None:
pass
a = A()
[builtins fixtures/property.pyi]
2 changes: 1 addition & 1 deletion test-data/unit/fixtures/property.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class object:
def __init__(self) -> None: pass

class type:
def __init__(self, x) -> None: pass
def __init__(self, x: typing.Any) -> None: pass

class function: pass

Expand Down
2 changes: 1 addition & 1 deletion test-data/unit/lib-stub/typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class Generator(Iterator[T], Generic[T, U, V]):
def send(self, value: U) -> T: pass

@abstractmethod
def throw(self, typ: Any, val: Any=None, tb=None) -> None: pass
def throw(self, typ: Any, val: Any = None, tb: Any = None) -> None: pass

@abstractmethod
def close(self) -> None: pass
Expand Down