From 0cc20773c603b812c1ed2a7d96d40b22dd261e19 Mon Sep 17 00:00:00 2001 From: Ivan Levkivskyi Date: Sun, 13 Nov 2016 22:05:21 +0100 Subject: [PATCH 1/2] On fix-alias-crashes: Union Any --- mypy/subtypes.py | 3 ++- test-data/unit/check-unions.test | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/mypy/subtypes.py b/mypy/subtypes.py index a046cef23d68..bfb3c4b58e87 100644 --- a/mypy/subtypes.py +++ b/mypy/subtypes.py @@ -345,7 +345,8 @@ def restrict_subtype_away(t: Type, s: Type) -> Type: Currently just remove elements of a union type. """ if isinstance(t, UnionType): - new_items = [item for item in t.items if not is_subtype(item, s)] + new_items = [item for item in t.items if (not is_subtype(item, s) + or isinstance(item, AnyType))] return UnionType.make_union(new_items) else: return t diff --git a/test-data/unit/check-unions.test b/test-data/unit/check-unions.test index 121413836014..d55585a15fb3 100644 --- a/test-data/unit/check-unions.test +++ b/test-data/unit/check-unions.test @@ -35,6 +35,17 @@ def f(x: Union[int, str]) -> None: [out] main: note: In function "f": +[case testUnionAnyIsInstance] +from typing import Any, Union + +def func(v:Union[int, Any]) -> None: + if isinstance(v, int): + reveal_type(v) # E: Revealed type is 'builins.int' + else: + reveal_type(v) # E: Revealed type is 'Any' +[builtins fixtures/isinstance.pyi] +[out] +main: note: In function "func": [case testUnionAttributeAccess] from typing import Union From 7a7de5bce9ba298d9819532b525bc60ee6de2019 Mon Sep 17 00:00:00 2001 From: Ivan Levkivskyi Date: Sun, 13 Nov 2016 22:27:46 +0100 Subject: [PATCH 2/2] Fix typo in test --- test-data/unit/check-unions.test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-data/unit/check-unions.test b/test-data/unit/check-unions.test index d55585a15fb3..3b2ea8f19f83 100644 --- a/test-data/unit/check-unions.test +++ b/test-data/unit/check-unions.test @@ -40,7 +40,7 @@ from typing import Any, Union def func(v:Union[int, Any]) -> None: if isinstance(v, int): - reveal_type(v) # E: Revealed type is 'builins.int' + reveal_type(v) # E: Revealed type is 'builtins.int' else: reveal_type(v) # E: Revealed type is 'Any' [builtins fixtures/isinstance.pyi]