@@ -671,9 +671,11 @@ C().g = "x" # E: function __main__.C.g is deprecated: use g2 instead \
671
671
[case testDeprecatedDescriptor]
672
672
# flags: --enable-error-code=deprecated
673
673
674
- from typing import Any, Optional, Union , overload
674
+ from typing import Any, Generic, Optional , overload, TypeVar, Union
675
675
from typing_extensions import deprecated
676
676
677
+ T = TypeVar("T")
678
+
677
679
@deprecated("use E1 instead")
678
680
class D1:
679
681
def __get__(self, obj: Optional[C], objtype: Any) -> Union[D1, int]: ...
@@ -701,10 +703,19 @@ class D3:
701
703
def __set__(self, obj: C, value: str) -> None: ...
702
704
def __set__(self, obj: C, value: Union[int, str]) -> None: ...
703
705
706
+ class D4(Generic[T]):
707
+ @overload
708
+ def __get__(self, obj: None, objtype: Any) -> T: ...
709
+ @overload
710
+ @deprecated("deprecated instance access")
711
+ def __get__(self, obj: C, objtype: Any) -> T: ...
712
+ def __get__(self, obj: Optional[C], objtype: Any) -> T: ...
713
+
704
714
class C:
705
715
d1 = D1() # E: class __main__.D1 is deprecated: use E1 instead
706
716
d2 = D2()
707
717
d3 = D3()
718
+ d4 = D4[int]()
708
719
709
720
c: C
710
721
C.d1
@@ -719,15 +730,21 @@ C.d3 # E: overload def (self: __main__.D3, obj: None, objtype: Any) -> __main__
719
730
c.d3 # E: overload def (self: __main__.D3, obj: __main__.C, objtype: Any) -> builtins.int of function __main__.D3.__get__ is deprecated: use E3.__get__ instead
720
731
c.d3 = 1
721
732
c.d3 = "x" # E: overload def (self: __main__.D3, obj: __main__.C, value: builtins.str) of function __main__.D3.__set__ is deprecated: use E3.__set__ instead
733
+
734
+ C.d4
735
+ c.d4 # E: overload def (self: __main__.D4[T`1], obj: __main__.C, objtype: Any) -> T`1 of function __main__.D4.__get__ is deprecated: deprecated instance access
722
736
[builtins fixtures/property.pyi]
723
737
724
738
725
739
[case testDeprecatedOverloadedFunction]
726
740
# flags: --enable-error-code=deprecated
727
741
728
- from typing import Union , overload
742
+ from typing import Any , overload, Union
729
743
from typing_extensions import deprecated
730
744
745
+ int_or_str: Union[int, str]
746
+ any: Any
747
+
731
748
@overload
732
749
def f(x: int) -> int: ...
733
750
@overload
@@ -738,6 +755,8 @@ def f(x: Union[int, str]) -> Union[int, str]: ...
738
755
f # E: function __main__.f is deprecated: use f2 instead
739
756
f(1) # E: function __main__.f is deprecated: use f2 instead
740
757
f("x") # E: function __main__.f is deprecated: use f2 instead
758
+ f(int_or_str) # E: function __main__.f is deprecated: use f2 instead
759
+ f(any) # E: function __main__.f is deprecated: use f2 instead
741
760
f(1.0) # E: function __main__.f is deprecated: use f2 instead \
742
761
# E: No overload variant of "f" matches argument type "float" \
743
762
# N: Possible overload variants: \
@@ -754,6 +773,8 @@ def g(x: Union[int, str]) -> Union[int, str]: ...
754
773
g
755
774
g(1) # E: overload def (x: builtins.int) -> builtins.int of function __main__.g is deprecated: work with str instead
756
775
g("x")
776
+ g(int_or_str) # E: overload def (x: builtins.int) -> builtins.int of function __main__.g is deprecated: work with str instead
777
+ g(any)
757
778
g(1.0) # E: No overload variant of "g" matches argument type "float" \
758
779
# N: Possible overload variants: \
759
780
# N: def g(x: int) -> int \
@@ -769,13 +790,62 @@ def h(x: Union[int, str]) -> Union[int, str]: ...
769
790
h
770
791
h(1)
771
792
h("x") # E: overload def (x: builtins.str) -> builtins.str of function __main__.h is deprecated: work with int instead
793
+ h(int_or_str) # E: overload def (x: builtins.str) -> builtins.str of function __main__.h is deprecated: work with int instead
794
+ h(any)
772
795
h(1.0) # E: No overload variant of "h" matches argument type "float" \
773
796
# N: Possible overload variants: \
774
797
# N: def h(x: int) -> int \
775
798
# N: def h(x: str) -> str
776
799
777
- [builtins fixtures/tuple.pyi]
800
+ @overload
801
+ def i(x: int) -> int: ...
802
+ @overload
803
+ @deprecated("work with int instead")
804
+ def i(x: str) -> str: ...
805
+ @overload
806
+ def i(x: Any) -> Any: ...
807
+ def i(x: Union[int, str]) -> Union[int, str]: ...
778
808
809
+ i
810
+ i(1)
811
+ i("x") # E: overload def (x: builtins.str) -> builtins.str of function __main__.i is deprecated: work with int instead
812
+ i(int_or_str) # E: overload def (x: builtins.str) -> builtins.str of function __main__.i is deprecated: work with int instead
813
+ i(any)
814
+ i(1.0)
815
+
816
+ @overload
817
+ def j(x: int) -> int: ...
818
+ @overload
819
+ def j(x: str) -> str: ...
820
+ @overload
821
+ @deprecated("work with int or str instead")
822
+ def j(x: Any) -> Any: ...
823
+ def j(x: Union[int, str]) -> Union[int, str]: ...
824
+
825
+ j
826
+ j(1)
827
+ j("x")
828
+ j(int_or_str)
829
+ j(any)
830
+ j(1.0) # E: overload def (x: Any) -> Any of function __main__.j is deprecated: work with int or str instead
831
+
832
+ @overload
833
+ @deprecated("work with str instead")
834
+ def k(x: int) -> int: ...
835
+ @overload
836
+ def k(x: str) -> str: ...
837
+ @overload
838
+ @deprecated("work with str instead")
839
+ def k(x: object) -> Any: ...
840
+ def k(x: object) -> Union[int, str]: ...
841
+
842
+ k
843
+ k(1) # E: overload def (x: builtins.int) -> builtins.int of function __main__.k is deprecated: work with str instead
844
+ k("x")
845
+ k(int_or_str) # E: overload def (x: builtins.int) -> builtins.int of function __main__.k is deprecated: work with str instead
846
+ k(any)
847
+ k(1.0) # E: overload def (x: builtins.object) -> Any of function __main__.k is deprecated: work with str instead
848
+ [builtins fixtures/tuple.pyi]
779
849
780
850
[case testDeprecatedImportedOverloadedFunction]
781
851
# flags: --enable-error-code=deprecated
0 commit comments