From 7bd5be4b72499b5d1886ed3fdf9768d093f123b6 Mon Sep 17 00:00:00 2001 From: detachhead Date: Tue, 2 Nov 2021 09:19:10 +1000 Subject: [PATCH 1/2] add testTypeVarBoundToNewUnionAttributeAccess --- test-data/unit/check-generic-subtyping.test | 30 ++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/test-data/unit/check-generic-subtyping.test b/test-data/unit/check-generic-subtyping.test index c16fadafab87..480532260663 100644 --- a/test-data/unit/check-generic-subtyping.test +++ b/test-data/unit/check-generic-subtyping.test @@ -818,7 +818,7 @@ class Y(Generic[T]): return U() # E: Incompatible return value type (got "U", expected "T") -[case testTypeVarBoundToUnionAttributeAccess] +[case testTypeVarBoundToOldUnionAttributeAccess] from typing import Union, TypeVar class U: @@ -844,6 +844,34 @@ main:15: error: Item "U" of the upper bound "Union[U, V, W]" of type variable "T main:15: error: Item "V" of the upper bound "Union[U, V, W]" of type variable "T" has no attribute "c" +[case testTypeVarBoundToNewUnionAttributeAccess] +# flags: --python-version 3.10 +from typing import TypeVar + +class U: + a: int +class V: + b: int +class W: + c: int + +T = TypeVar("T", bound=U | V | W) + +def f(x: T) -> None: + x.a # E + x.b = 1 # E + del x.c # E + +[builtins fixtures/tuple.pyi] +[out] +main:13: error: Item "V" of the upper bound "Union[U, V, W]" of type variable "T" has no attribute "a" +main:13: error: Item "W" of the upper bound "Union[U, V, W]" of type variable "T" has no attribute "a" +main:14: error: Item "U" of the upper bound "Union[U, V, W]" of type variable "T" has no attribute "b" +main:14: error: Item "W" of the upper bound "Union[U, V, W]" of type variable "T" has no attribute "b" +main:15: error: Item "U" of the upper bound "Union[U, V, W]" of type variable "T" has no attribute "c" +main:15: error: Item "V" of the upper bound "Union[U, V, W]" of type variable "T" has no attribute "c" + + [case testSubtypingIterableUnpacking1] # https://github.com/python/mypy/issues/11138 from typing import Generic, Iterator, TypeVar From 44ffcc6139ad82d4d631073b510d3ad4626b1589 Mon Sep 17 00:00:00 2001 From: detachhead Date: Wed, 3 Nov 2021 21:36:26 +1000 Subject: [PATCH 2/2] add testTypeVarBoundToNewUnionAttributeAccess --- test-data/unit/check-generic-subtyping.test | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test-data/unit/check-generic-subtyping.test b/test-data/unit/check-generic-subtyping.test index 480532260663..f97e3015fa32 100644 --- a/test-data/unit/check-generic-subtyping.test +++ b/test-data/unit/check-generic-subtyping.test @@ -864,12 +864,12 @@ def f(x: T) -> None: [builtins fixtures/tuple.pyi] [out] -main:13: error: Item "V" of the upper bound "Union[U, V, W]" of type variable "T" has no attribute "a" -main:13: error: Item "W" of the upper bound "Union[U, V, W]" of type variable "T" has no attribute "a" -main:14: error: Item "U" of the upper bound "Union[U, V, W]" of type variable "T" has no attribute "b" -main:14: error: Item "W" of the upper bound "Union[U, V, W]" of type variable "T" has no attribute "b" -main:15: error: Item "U" of the upper bound "Union[U, V, W]" of type variable "T" has no attribute "c" -main:15: error: Item "V" of the upper bound "Union[U, V, W]" of type variable "T" has no attribute "c" +main:14: error: Item "V" of the upper bound "Union[U, V, W]" of type variable "T" has no attribute "a" +main:14: error: Item "W" of the upper bound "Union[U, V, W]" of type variable "T" has no attribute "a" +main:15: error: Item "U" of the upper bound "Union[U, V, W]" of type variable "T" has no attribute "b" +main:15: error: Item "W" of the upper bound "Union[U, V, W]" of type variable "T" has no attribute "b" +main:16: error: Item "U" of the upper bound "Union[U, V, W]" of type variable "T" has no attribute "c" +main:16: error: Item "V" of the upper bound "Union[U, V, W]" of type variable "T" has no attribute "c" [case testSubtypingIterableUnpacking1]