From f00c1c672493d6f3efc898489415946bb14ffce3 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Fri, 2 Jun 2017 08:31:51 -0700 Subject: [PATCH 1/3] fix crash when serializing a type-ignored property setter This fixes the crash from #3491. I wasn't able to reproduce the crash in a test, even with '# flags: --incremental', so I'm not adding any new tests. Do I need some special flags to make tests write the cache? --- mypy/semanal.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mypy/semanal.py b/mypy/semanal.py index 0d74b7558c23..b337cec6b950 100644 --- a/mypy/semanal.py +++ b/mypy/semanal.py @@ -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) + if isinstance(item, Decorator): + item.func.accept(self) def analyze_function(self, defn: FuncItem) -> None: is_method = self.is_class_scope() From 81478f4ba357977f69dd5f653089f6d61dce988d Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Fri, 2 Jun 2017 19:34:06 -0700 Subject: [PATCH 2/3] Add tests Turns out the cache isn't written if there is any error, and I had a reveal_type which counts as an error. The change fixes both bugs from the original issue: - Without --disallow-untyped-defs, it no longer crashes during cache serialization. - With --disallow-untyped-defs, it no longer produces a spurious error because "self" doesn't have an annotation. --- test-data/unit/check-incremental.test | 29 +++++++++++++++++++++++++++ test-data/unit/fixtures/property.pyi | 2 +- test-data/unit/lib-stub/typing.pyi | 2 +- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/test-data/unit/check-incremental.test b/test-data/unit/check-incremental.test index 5256c362531b..d28cb1acf512 100644 --- a/test-data/unit/check-incremental.test +++ b/test-data/unit/check-incremental.test @@ -2684,3 +2684,32 @@ b.x.y [out3] tmp/c.py:2: error: Revealed type is '' tmp/c.py:5: error: "" 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] diff --git a/test-data/unit/fixtures/property.pyi b/test-data/unit/fixtures/property.pyi index 994874b93b79..929317e2ef66 100644 --- a/test-data/unit/fixtures/property.pyi +++ b/test-data/unit/fixtures/property.pyi @@ -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 diff --git a/test-data/unit/lib-stub/typing.pyi b/test-data/unit/lib-stub/typing.pyi index 58b28836bf69..cd369d0c4891 100644 --- a/test-data/unit/lib-stub/typing.pyi +++ b/test-data/unit/lib-stub/typing.pyi @@ -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 From 480445b7c22251f8afc58b42f8af4158befe6204 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Fri, 2 Jun 2017 20:45:31 -0700 Subject: [PATCH 3/3] Conform to PEP 8. --- test-data/unit/lib-stub/typing.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-data/unit/lib-stub/typing.pyi b/test-data/unit/lib-stub/typing.pyi index cd369d0c4891..274f3da76164 100644 --- a/test-data/unit/lib-stub/typing.pyi +++ b/test-data/unit/lib-stub/typing.pyi @@ -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: Any=None) -> None: pass + def throw(self, typ: Any, val: Any = None, tb: Any = None) -> None: pass @abstractmethod def close(self) -> None: pass