Skip to content

Commit ed847a8

Browse files
committed
restore some test (test changes) that I stashed accidentally
1 parent 6528fc5 commit ed847a8

File tree

1 file changed

+72
-2
lines changed

1 file changed

+72
-2
lines changed

test-data/unit/check-deprecated.test

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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
675675
from typing_extensions import deprecated
676676

677+
T = TypeVar("T")
678+
677679
@deprecated("use E1 instead")
678680
class 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+
704714
class C:
705715
d1 = D1() # E: class __main__.D1 is deprecated: use E1 instead
706716
d2 = D2()
707717
d3 = D3()
718+
d4 = D4[int]()
708719

709720
c: C
710721
C.d1
@@ -719,15 +730,21 @@ C.d3 # E: overload def (self: __main__.D3, obj: None, objtype: Any) -> __main__
719730
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
720731
c.d3 = 1
721732
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
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
729743
from typing_extensions import deprecated
730744

745+
int_or_str: Union[int, str]
746+
any: Any
747+
731748
@overload
732749
def f(x: int) -> int: ...
733750
@overload
@@ -738,6 +755,8 @@ def f(x: Union[int, str]) -> Union[int, str]: ...
738755
f # E: function __main__.f is deprecated: use f2 instead
739756
f(1) # E: function __main__.f is deprecated: use f2 instead
740757
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
741760
f(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]: ...
754773
g
755774
g(1) # E: overload def (x: builtins.int) -> builtins.int of function __main__.g is deprecated: work with str instead
756775
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)
757778
g(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,14 +790,63 @@ def h(x: Union[int, str]) -> Union[int, str]: ...
769790
h
770791
h(1)
771792
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)
772795
h(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

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]: ...
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+
777816
[builtins fixtures/tuple.pyi]
778817

818+
@overload
819+
def j(x: int) -> int: ...
820+
@overload
821+
def j(x: str) -> str: ...
822+
@overload
823+
@deprecated("work with int or str instead")
824+
def j(x: Any) -> Any: ...
825+
def j(x: Union[int, str]) -> Union[int, str]: ...
826+
827+
j
828+
j(1)
829+
j("x")
830+
j(int_or_str)
831+
j(any) # E: overload def (x: builtins.str) -> builtins.str of function __main__.i is deprecated: work with int or str instead
832+
j(1.0)
779833

834+
@overload
835+
@deprecated("work with str instead")
836+
def k(x: int) -> int: ...
837+
@overload
838+
def k(x: str) -> str: ...
839+
@overload
840+
@deprecated("work with str instead")
841+
def k(x: object) -> Any: ...
842+
def k(x: Union[int, str]) -> Union[int, str]: ...
843+
844+
k
845+
k(1)
846+
k("x")
847+
k(int_or_str)
848+
k(any) # E: overload def (x: builtins.str) -> builtins.str of function __main__.i is deprecated: work with int or str instead
849+
k(1.0)
780850
[case testDeprecatedImportedOverloadedFunction]
781851
# flags: --enable-error-code=deprecated
782852

0 commit comments

Comments
 (0)