Skip to content

Commit 5302af3

Browse files
committed
add incremental test for calling deprecated constructors
1 parent 79d0cb0 commit 5302af3

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

test-data/unit/check-incremental.test

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7512,3 +7512,91 @@ tmp/impl.py:31: note: Revealed type is "builtins.object"
75127512
tmp/impl.py:32: note: Revealed type is "Union[builtins.int, builtins.str, lib.Unrelated]"
75137513
tmp/impl.py:33: note: Revealed type is "builtins.object"
75147514
tmp/impl.py:34: note: Revealed type is "builtins.object"
7515+
7516+
7517+
[case testIncrementalDeprecatedClassConstructorCallExpressions]
7518+
# flags: --enable-error-code=deprecated
7519+
7520+
# Tests whether adding/removing `@deprecated()` on class constructors correctly update
7521+
# when the call is from a class, the class's children, and from type aliases.
7522+
# Addition/removal is emulated by setting up 2 parent classes across 3 versions of `mod.py`.
7523+
# `Parent1.__init__` has `@deprecated()`: yes/no/yes in v1/v2/v3, respectively.
7524+
# `Parent2.__init__` has `@deprecated()`: no/yes/no in v1/v2/v3, respectively.
7525+
7526+
from typing_extensions import TypeAlias
7527+
import mod
7528+
7529+
Parent1_alias: TypeAlias = mod.Parent1
7530+
Parent1_type_obj: type[mod.Parent1]
7531+
Parent2_alias: TypeAlias = mod.Parent2
7532+
Parent2_type_obj: type[mod.Parent2]
7533+
class Child1_of_Parent1(mod.Parent1): ...
7534+
class Child1_of_Parent2(mod.Parent2): ...
7535+
7536+
# Emits errors in v1 and v3
7537+
Parent1_alias()
7538+
Parent1_type_obj()
7539+
Child1_of_Parent1()
7540+
class Child2_of_Parent1(mod.Parent1):
7541+
def __init__(self) -> None:
7542+
super().__init__()
7543+
7544+
# Emits errors in v2 only
7545+
Parent2_alias()
7546+
Parent2_type_obj()
7547+
Child1_of_Parent2()
7548+
class Child2_of_Parent2(mod.Parent2):
7549+
def __init__(self) -> None:
7550+
super().__init__()
7551+
7552+
# Never emits errors
7553+
Child2_of_Parent1()
7554+
Child2_of_Parent2()
7555+
7556+
[file mod.py]
7557+
from typing_extensions import TypeAlias, deprecated
7558+
7559+
class Parent1:
7560+
@deprecated("v1: do not use Parent1.__init__")
7561+
def __init__(self) -> None: ...
7562+
7563+
class Parent2:
7564+
def __init__(self) -> None: ...
7565+
7566+
[file mod.py.2]
7567+
from typing_extensions import TypeAlias, deprecated
7568+
7569+
class Parent1:
7570+
def __init__(self) -> None: ...
7571+
7572+
class Parent2:
7573+
@deprecated("v2: do not use Parent2.__init__")
7574+
def __init__(self) -> None: ...
7575+
7576+
[file mod.py.3]
7577+
from typing_extensions import TypeAlias, deprecated
7578+
7579+
class Parent1:
7580+
@deprecated("v3: do not use Parent1.__init__")
7581+
def __init__(self) -> None: ...
7582+
7583+
class Parent2:
7584+
def __init__(self) -> None: ...
7585+
7586+
[builtins fixtures/tuple.pyi]
7587+
[stale mod]
7588+
[out]
7589+
main:20: error: function mod.Parent1.__init__ is deprecated: v1: do not use Parent1.__init__
7590+
main:21: error: function mod.Parent1.__init__ is deprecated: v1: do not use Parent1.__init__
7591+
main:22: error: function mod.Parent1.__init__ is deprecated: v1: do not use Parent1.__init__
7592+
main:25: error: function mod.Parent1.__init__ is deprecated: v1: do not use Parent1.__init__
7593+
[out2]
7594+
main:28: error: function mod.Parent2.__init__ is deprecated: v2: do not use Parent2.__init__
7595+
main:29: error: function mod.Parent2.__init__ is deprecated: v2: do not use Parent2.__init__
7596+
main:30: error: function mod.Parent2.__init__ is deprecated: v2: do not use Parent2.__init__
7597+
main:33: error: function mod.Parent2.__init__ is deprecated: v2: do not use Parent2.__init__
7598+
[out3]
7599+
main:20: error: function mod.Parent1.__init__ is deprecated: v3: do not use Parent1.__init__
7600+
main:21: error: function mod.Parent1.__init__ is deprecated: v3: do not use Parent1.__init__
7601+
main:22: error: function mod.Parent1.__init__ is deprecated: v3: do not use Parent1.__init__
7602+
main:25: error: function mod.Parent1.__init__ is deprecated: v3: do not use Parent1.__init__

0 commit comments

Comments
 (0)