@@ -671,9 +671,11 @@ C().g = "x" # E: function __main__.C.g is deprecated: use g2 instead \
671671[case testDeprecatedDescriptor]
672672# flags: --enable-error-code=deprecated
673673
674- from typing import Any, Optional, Union , overload
674+ from typing import Any, Generic, Optional , overload, TypeVar, Union
675675from typing_extensions import deprecated
676676
677+ T = TypeVar("T")
678+
677679@deprecated("use E1 instead")
678680class D1:
679681 def __get__(self, obj: Optional[C], objtype: Any) -> Union[D1, int]: ...
@@ -701,10 +703,19 @@ class D3:
701703 def __set__(self, obj: C, value: str) -> None: ...
702704 def __set__(self, obj: C, value: Union[int, str]) -> None: ...
703705
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+
704714class C:
705715 d1 = D1() # E: class __main__.D1 is deprecated: use E1 instead
706716 d2 = D2()
707717 d3 = D3()
718+ d4 = D4[int]()
708719
709720c: C
710721C.d1
@@ -719,15 +730,21 @@ C.d3 # E: overload def (self: __main__.D3, obj: None, objtype: Any) -> __main__
719730c.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
720731c.d3 = 1
721732c.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
722736[builtins fixtures/property.pyi]
723737
724738
725739[case testDeprecatedOverloadedFunction]
726740# flags: --enable-error-code=deprecated
727741
728- from typing import Union , overload
742+ from typing import Any , overload, Union
729743from typing_extensions import deprecated
730744
745+ int_or_str: Union[int, str]
746+ any: Any
747+
731748@overload
732749def f(x: int) -> int: ...
733750@overload
@@ -738,6 +755,8 @@ def f(x: Union[int, str]) -> Union[int, str]: ...
738755f # E: function __main__.f is deprecated: use f2 instead
739756f(1) # E: function __main__.f is deprecated: use f2 instead
740757f("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
741760f(1.0) # E: function __main__.f is deprecated: use f2 instead \
742761 # E: No overload variant of "f" matches argument type "float" \
743762 # N: Possible overload variants: \
@@ -754,6 +773,8 @@ def g(x: Union[int, str]) -> Union[int, str]: ...
754773g
755774g(1) # E: overload def (x: builtins.int) -> builtins.int of function __main__.g is deprecated: work with str instead
756775g("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)
757778g(1.0) # E: No overload variant of "g" matches argument type "float" \
758779 # N: Possible overload variants: \
759780 # N: def g(x: int) -> int \
@@ -769,13 +790,62 @@ def h(x: Union[int, str]) -> Union[int, str]: ...
769790h
770791h(1)
771792h("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)
772795h(1.0) # E: No overload variant of "h" matches argument type "float" \
773796 # N: Possible overload variants: \
774797 # N: def h(x: int) -> int \
775798 # N: def h(x: str) -> str
776799
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]: ...
778808
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]
779849
780850[case testDeprecatedImportedOverloadedFunction]
781851# flags: --enable-error-code=deprecated
0 commit comments