@@ -7311,3 +7311,204 @@ x = 2
73117311[out]
73127312[rechecked bar]
73137313[stale]
7314+
7315+
7316+ [case testIncrementalTypedDictGetMethodTotalFalse]
7317+ import impl
7318+ [file lib.py]
7319+ from typing import TypedDict
7320+ class Unrelated: pass
7321+ D = TypedDict('D', {'x': int, 'y': str}, total=False)
7322+ [file impl.py]
7323+ pass
7324+ [file impl.py.2]
7325+ from typing import Literal
7326+ from lib import D, Unrelated
7327+ d: D
7328+ u: Unrelated
7329+ x: Literal['x']
7330+ y: Literal['y']
7331+ z: Literal['z']
7332+ x_or_y: Literal['x', 'y']
7333+ x_or_z: Literal['x', 'z']
7334+ x_or_y_or_z: Literal['x', 'y', 'z']
7335+
7336+ # test with literal expression
7337+ reveal_type(d.get('x'))
7338+ reveal_type(d.get('y'))
7339+ reveal_type(d.get('z'))
7340+ reveal_type(d.get('x', u))
7341+ reveal_type(d.get('x', 1))
7342+ reveal_type(d.get('y', None))
7343+
7344+ # test with literal type / union of literal types with implicit default
7345+ reveal_type(d.get(x))
7346+ reveal_type(d.get(y))
7347+ reveal_type(d.get(z))
7348+ reveal_type(d.get(x_or_y))
7349+ reveal_type(d.get(x_or_z))
7350+ reveal_type(d.get(x_or_y_or_z))
7351+
7352+ # test with literal type / union of literal types with explicit default
7353+ reveal_type(d.get(x, u))
7354+ reveal_type(d.get(y, u))
7355+ reveal_type(d.get(z, u))
7356+ reveal_type(d.get(x_or_y, u))
7357+ reveal_type(d.get(x_or_z, u))
7358+ reveal_type(d.get(x_or_y_or_z, u))
7359+ [builtins fixtures/dict.pyi]
7360+ [typing fixtures/typing-typeddict.pyi]
7361+ [out]
7362+ [out2]
7363+ tmp/impl.py:13: note: Revealed type is "Union[builtins.int, None]"
7364+ tmp/impl.py:14: note: Revealed type is "Union[builtins.str, None]"
7365+ tmp/impl.py:15: note: Revealed type is "builtins.object"
7366+ tmp/impl.py:16: note: Revealed type is "Union[builtins.int, lib.Unrelated]"
7367+ tmp/impl.py:17: note: Revealed type is "builtins.int"
7368+ tmp/impl.py:18: note: Revealed type is "Union[builtins.str, None]"
7369+ tmp/impl.py:21: note: Revealed type is "Union[builtins.int, None]"
7370+ tmp/impl.py:22: note: Revealed type is "Union[builtins.str, None]"
7371+ tmp/impl.py:23: note: Revealed type is "builtins.object"
7372+ tmp/impl.py:24: note: Revealed type is "Union[builtins.int, builtins.str, None]"
7373+ tmp/impl.py:25: note: Revealed type is "builtins.object"
7374+ tmp/impl.py:26: note: Revealed type is "builtins.object"
7375+ tmp/impl.py:29: note: Revealed type is "Union[builtins.int, lib.Unrelated]"
7376+ tmp/impl.py:30: note: Revealed type is "Union[builtins.str, lib.Unrelated]"
7377+ tmp/impl.py:31: note: Revealed type is "builtins.object"
7378+ tmp/impl.py:32: note: Revealed type is "Union[builtins.int, builtins.str, lib.Unrelated]"
7379+ tmp/impl.py:33: note: Revealed type is "builtins.object"
7380+ tmp/impl.py:34: note: Revealed type is "builtins.object"
7381+
7382+ [case testIncrementalTypedDictGetMethodTotalTrue]
7383+ import impl
7384+ [file lib.py]
7385+ from typing import TypedDict
7386+ class Unrelated: pass
7387+ D = TypedDict('D', {'x': int, 'y': str}, total=True)
7388+ [file impl.py]
7389+ pass
7390+ [file impl.py.2]
7391+ from typing import Literal
7392+ from lib import D, Unrelated
7393+ d: D
7394+ u: Unrelated
7395+ x: Literal['x']
7396+ y: Literal['y']
7397+ z: Literal['z']
7398+ x_or_y: Literal['x', 'y']
7399+ x_or_z: Literal['x', 'z']
7400+ x_or_y_or_z: Literal['x', 'y', 'z']
7401+
7402+ # test with literal expression
7403+ reveal_type(d.get('x'))
7404+ reveal_type(d.get('y'))
7405+ reveal_type(d.get('z'))
7406+ reveal_type(d.get('x', u))
7407+ reveal_type(d.get('x', 1))
7408+ reveal_type(d.get('y', None))
7409+
7410+ # test with literal type / union of literal types with implicit default
7411+ reveal_type(d.get(x))
7412+ reveal_type(d.get(y))
7413+ reveal_type(d.get(z))
7414+ reveal_type(d.get(x_or_y))
7415+ reveal_type(d.get(x_or_z))
7416+ reveal_type(d.get(x_or_y_or_z))
7417+
7418+ # test with literal type / union of literal types with explicit default
7419+ reveal_type(d.get(x, u))
7420+ reveal_type(d.get(y, u))
7421+ reveal_type(d.get(z, u))
7422+ reveal_type(d.get(x_or_y, u))
7423+ reveal_type(d.get(x_or_z, u))
7424+ reveal_type(d.get(x_or_y_or_z, u))
7425+ [builtins fixtures/dict.pyi]
7426+ [typing fixtures/typing-typeddict.pyi]
7427+ [out]
7428+ [out2]
7429+ tmp/impl.py:13: note: Revealed type is "builtins.int"
7430+ tmp/impl.py:14: note: Revealed type is "builtins.str"
7431+ tmp/impl.py:15: note: Revealed type is "builtins.object"
7432+ tmp/impl.py:16: note: Revealed type is "builtins.int"
7433+ tmp/impl.py:17: note: Revealed type is "builtins.int"
7434+ tmp/impl.py:18: note: Revealed type is "builtins.str"
7435+ tmp/impl.py:21: note: Revealed type is "builtins.int"
7436+ tmp/impl.py:22: note: Revealed type is "builtins.str"
7437+ tmp/impl.py:23: note: Revealed type is "builtins.object"
7438+ tmp/impl.py:24: note: Revealed type is "Union[builtins.int, builtins.str]"
7439+ tmp/impl.py:25: note: Revealed type is "builtins.object"
7440+ tmp/impl.py:26: note: Revealed type is "builtins.object"
7441+ tmp/impl.py:29: note: Revealed type is "builtins.int"
7442+ tmp/impl.py:30: note: Revealed type is "builtins.str"
7443+ tmp/impl.py:31: note: Revealed type is "builtins.object"
7444+ tmp/impl.py:32: note: Revealed type is "Union[builtins.int, builtins.str]"
7445+ tmp/impl.py:33: note: Revealed type is "builtins.object"
7446+ tmp/impl.py:34: note: Revealed type is "builtins.object"
7447+
7448+
7449+ [case testIncrementalTypedDictGetMethodTotalMixed]
7450+ import impl
7451+ [file lib.py]
7452+ from typing import TypedDict
7453+ from typing_extensions import Required, NotRequired
7454+ class Unrelated: pass
7455+ D = TypedDict('D', {'x': Required[int], 'y': NotRequired[str]})
7456+ [file impl.py]
7457+ pass
7458+ [file impl.py.2]
7459+ from typing import Literal
7460+ from lib import D, Unrelated
7461+ d: D
7462+ u: Unrelated
7463+ x: Literal['x']
7464+ y: Literal['y']
7465+ z: Literal['z']
7466+ x_or_y: Literal['x', 'y']
7467+ x_or_z: Literal['x', 'z']
7468+ x_or_y_or_z: Literal['x', 'y', 'z']
7469+
7470+ # test with literal expression
7471+ reveal_type(d.get('x'))
7472+ reveal_type(d.get('y'))
7473+ reveal_type(d.get('z'))
7474+ reveal_type(d.get('x', u))
7475+ reveal_type(d.get('x', 1))
7476+ reveal_type(d.get('y', None))
7477+
7478+ # test with literal type / union of literal types with implicit default
7479+ reveal_type(d.get(x))
7480+ reveal_type(d.get(y))
7481+ reveal_type(d.get(z))
7482+ reveal_type(d.get(x_or_y))
7483+ reveal_type(d.get(x_or_z))
7484+ reveal_type(d.get(x_or_y_or_z))
7485+
7486+ # test with literal type / union of literal types with explicit default
7487+ reveal_type(d.get(x, u))
7488+ reveal_type(d.get(y, u))
7489+ reveal_type(d.get(z, u))
7490+ reveal_type(d.get(x_or_y, u))
7491+ reveal_type(d.get(x_or_z, u))
7492+ reveal_type(d.get(x_or_y_or_z, u))
7493+ [builtins fixtures/dict.pyi]
7494+ [typing fixtures/typing-typeddict.pyi]
7495+ [out]
7496+ [out2]
7497+ tmp/impl.py:13: note: Revealed type is "builtins.int"
7498+ tmp/impl.py:14: note: Revealed type is "Union[builtins.str, None]"
7499+ tmp/impl.py:15: note: Revealed type is "builtins.object"
7500+ tmp/impl.py:16: note: Revealed type is "builtins.int"
7501+ tmp/impl.py:17: note: Revealed type is "builtins.int"
7502+ tmp/impl.py:18: note: Revealed type is "Union[builtins.str, None]"
7503+ tmp/impl.py:21: note: Revealed type is "builtins.int"
7504+ tmp/impl.py:22: note: Revealed type is "Union[builtins.str, None]"
7505+ tmp/impl.py:23: note: Revealed type is "builtins.object"
7506+ tmp/impl.py:24: note: Revealed type is "Union[builtins.int, builtins.str, None]"
7507+ tmp/impl.py:25: note: Revealed type is "builtins.object"
7508+ tmp/impl.py:26: note: Revealed type is "builtins.object"
7509+ tmp/impl.py:29: note: Revealed type is "builtins.int"
7510+ tmp/impl.py:30: note: Revealed type is "Union[builtins.str, lib.Unrelated]"
7511+ tmp/impl.py:31: note: Revealed type is "builtins.object"
7512+ tmp/impl.py:32: note: Revealed type is "Union[builtins.int, builtins.str, lib.Unrelated]"
7513+ tmp/impl.py:33: note: Revealed type is "builtins.object"
7514+ tmp/impl.py:34: note: Revealed type is "builtins.object"
0 commit comments