@@ -939,6 +939,49 @@ class A:
939
939
a = A() # type: A
940
940
reveal_type(a.f) # E: Revealed type is 'Union[__main__.D, builtins.str]'
941
941
942
+ [case testAccessingGenericNonDataDescriptor]
943
+ from typing import TypeVar, Type, Generic
944
+
945
+ T = TypeVar('T')
946
+ V = TypeVar('V')
947
+ class D(Generic[T, V]):
948
+ def __init__(self, value: V) -> None:
949
+ self.value = value
950
+ def __get__(self, instance: T, owner: Type[T]) -> V:
951
+ return self.value
952
+
953
+ class A:
954
+ f = D(10) # type: D[A, int]
955
+ g = D('10') # type: D[A, str]
956
+
957
+ a = A() # type: A
958
+ reveal_type(a.f) # E: Revealed type is 'builtins.int*'
959
+ reveal_type(a.g) # E: Revealed type is 'builtins.str*'
960
+
961
+ [case testSettingGenericDataDescriptor]
962
+ from typing import TypeVar, Type, Generic
963
+
964
+ T = TypeVar('T')
965
+ V = TypeVar('V')
966
+ class D(Generic[T, V]):
967
+ def __init__(self, value: V) -> None:
968
+ self.value = value
969
+ def __get__(self, instance: T, owner: Type[T]) -> V:
970
+ return self.value
971
+ def __set__(self, instance: T, value: V) -> None:
972
+ pass
973
+
974
+ class A:
975
+ f = D(10) # type: D[A, int]
976
+ g = D('10') # type: D[A, str]
977
+
978
+ a = A() # type: A
979
+ a.f = 1
980
+ a.f = '' # E: Incompatible types in assignment (expression has type "str", variable has type "int")
981
+ a.g = ''
982
+ a.g = 1 # E: Incompatible types in assignment (expression has type "int", variable has type "str")
983
+
984
+
942
985
943
986
-- Multiple inheritance, non-object built-in class as base
944
987
-- -------------------------------------------------------
0 commit comments