Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions mypyc/test-data/irbuild-dict.test
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,7 @@ L0:
return r2

[case testDictIterationMethods]
from typing import Dict, Union
from typing_extensions import TypedDict
from typing import Dict, TypedDict, Union

class Person(TypedDict):
name: str
Expand All @@ -239,6 +238,7 @@ def typeddict(d: Person) -> None:
for k, v in d.items():
if k == "name":
name = v
[typing fixtures/typing-full.pyi]
[out]
def print_dict_methods(d1, d2):
d1, d2 :: dict
Expand Down
3 changes: 2 additions & 1 deletion mypyc/test-data/run-classes.test
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,15 @@ assert hasattr(c, 'x')

[case testTypedDictWithFields]
import collections
from typing_extensions import TypedDict
from typing import TypedDict
class C(TypedDict):
x: collections.deque
[file driver.py]
from native import C
from collections import deque

print(C.__annotations__["x"] is deque)
[typing fixtures/typing-full.pyi]
[out]
True

Expand Down
4 changes: 2 additions & 2 deletions mypyc/test-data/run-dicts.test
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ assert get_content_set(od) == ({1, 3}, {2, 4}, {(1, 2), (3, 4)})
[typing fixtures/typing-full.pyi]

[case testDictIterationMethodsRun]
from typing import Dict, Union
from typing_extensions import TypedDict
from typing import Dict, TypedDict, Union

class ExtensionDict(TypedDict):
python: str
Expand Down Expand Up @@ -188,6 +187,7 @@ except TypeError as e:
assert str(e) == "a tuple of length 2 expected"
else:
assert False
[typing fixtures/typing-full.pyi]
[out]
1
3
Expand Down
4 changes: 3 additions & 1 deletion mypyc/test-data/run-functions.test
Original file line number Diff line number Diff line change
Expand Up @@ -1243,7 +1243,8 @@ def g() -> None:
g()

[case testUnpackKwargsCompiled]
from typing_extensions import Unpack, TypedDict
from typing import TypedDict
from typing_extensions import Unpack

class Person(TypedDict):
name: str
Expand All @@ -1254,6 +1255,7 @@ def foo(**kwargs: Unpack[Person]) -> None:

# This is not really supported yet, just test that we behave reasonably.
foo(name='Jennifer', age=38)
[typing fixtures/typing-full.pyi]
[out]
Jennifer

Expand Down
8 changes: 5 additions & 3 deletions mypyc/test-data/run-misc.test
Original file line number Diff line number Diff line change
Expand Up @@ -612,8 +612,8 @@ for a in sorted(s):
9 8 72

[case testDummyTypes]
from typing import Tuple, List, Dict, Literal, NamedTuple
from typing_extensions import TypedDict, NewType
from typing import Tuple, List, Dict, Literal, NamedTuple, TypedDict
from typing_extensions import NewType

class A:
pass
Expand Down Expand Up @@ -664,6 +664,7 @@ except Exception as e:
print(type(e).__name__)
# ... but not that it is a valid literal value
take_literal(10)
[typing fixtures/typing-full.pyi]
[out]
Lol(a=1, b=[])
10
Expand All @@ -675,7 +676,7 @@ TypeError
10

[case testClassBasedTypedDict]
from typing_extensions import TypedDict
from typing import TypedDict

class TD(TypedDict):
a: int
Expand Down Expand Up @@ -707,6 +708,7 @@ def test_non_total_typed_dict() -> None:
d4 = TD4(a=1, b=2, c=3, d=4)
assert d3['c'] == 3
assert d4['d'] == 4
[typing fixtures/typing-full.pyi]

[case testClassBasedNamedTuple]
from typing import NamedTuple
Expand Down
9 changes: 4 additions & 5 deletions test-data/unit/check-basic.test
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,7 @@ y = x # E: Incompatible types in assignment (expression has type "Dict[str, int]
import b

[file a.py]
from typing import NamedTuple
from typing_extensions import TypedDict
from typing import NamedTuple, TypedDict
from enum import Enum
class A: pass
N = NamedTuple('N', [('x', int)])
Expand All @@ -406,8 +405,8 @@ class B(Enum):
b = 10

[file b.py]
from typing import List, Literal, Optional, Union, Sequence, NamedTuple, Tuple, Type
from typing_extensions import Final, TypedDict
from typing import List, Literal, Optional, Union, Sequence, NamedTuple, Tuple, Type, TypedDict
from typing_extensions import Final
from enum import Enum
import a
class A: pass
Expand Down Expand Up @@ -464,8 +463,8 @@ def typeddict() -> Sequence[D]:

a = (a.A(), A())
a.x # E: "Tuple[a.A, b.A]" has no attribute "x"

[builtins fixtures/dict.pyi]
[typing fixtures/typing-full.pyi]

[case testReturnAnyFromFunctionDeclaredToReturnObject]
# flags: --warn-return-any
Expand Down
3 changes: 2 additions & 1 deletion test-data/unit/check-dataclasses.test
Original file line number Diff line number Diff line change
Expand Up @@ -1408,7 +1408,7 @@ class C:

[case testDataclassFieldWithTypedDictUnpacking]
from dataclasses import dataclass, field
from typing_extensions import TypedDict
from typing import TypedDict

class FieldKwargs(TypedDict):
repr: bool
Expand All @@ -1421,6 +1421,7 @@ class Foo:

reveal_type(Foo(bar=1.5)) # N: Revealed type is "__main__.Foo"
[builtins fixtures/dataclasses.pyi]
[typing fixtures/typing-typeddict.pyi]

[case testDataclassWithSlotsArg]
# flags: --python-version 3.10
Expand Down
11 changes: 6 additions & 5 deletions test-data/unit/check-errorcodes.test
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ y: Dict[int, int] = {1: ''} # E: Dict entry 0 has incompatible type "int": "str
[builtins fixtures/dict.pyi]

[case testErrorCodeTypedDict]
from typing_extensions import TypedDict
from typing import TypedDict
class D(TypedDict):
x: int
class E(TypedDict):
Expand All @@ -472,7 +472,7 @@ a['y'] # E: TypedDict "D" has no key "y" [typeddict-item]
[typing fixtures/typing-typeddict.pyi]

[case testErrorCodeTypedDictNoteIgnore]
from typing_extensions import TypedDict
from typing import TypedDict
class A(TypedDict):
one_commonpart: int
two_commonparts: int
Expand All @@ -484,7 +484,7 @@ not_exist = a['not_exist'] # type: ignore[typeddict-item]
[typing fixtures/typing-typeddict.pyi]

[case testErrorCodeTypedDictSubCodeIgnore]
from typing_extensions import TypedDict
from typing import TypedDict
class D(TypedDict):
x: int
d: D = {'x': 1, 'y': 2} # type: ignore[typeddict-item]
Expand Down Expand Up @@ -831,10 +831,11 @@ Foo = NamedTuple("Bar", []) # E: First argument to namedtuple() should be "Foo"
[builtins fixtures/tuple.pyi]

[case testTypedDictNameMismatch]
from typing_extensions import TypedDict
from typing import TypedDict

Foo = TypedDict("Bar", {}) # E: First argument "Bar" to TypedDict() does not match variable name "Foo" [name-match]
[builtins fixtures/dict.pyi]
[typing fixtures/typing-typeddict.pyi]

[case testTruthyBool]
# flags: --enable-error-code truthy-bool --no-local-partial-types
Expand Down Expand Up @@ -993,7 +994,7 @@ reveal_type(t) # N: Revealed type is "__main__.TensorType"
[builtins fixtures/tuple.pyi]

[case testNoteAboutChangedTypedDictErrorCode]
from typing_extensions import TypedDict
from typing import TypedDict
class D(TypedDict):
x: int

Expand Down
3 changes: 2 additions & 1 deletion test-data/unit/check-formatting.test
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ x: Any
[builtins fixtures/primitives.pyi]

[case testFormatCallAccessorsIndices]
from typing_extensions import TypedDict
from typing import TypedDict

class User(TypedDict):
id: int
Expand All @@ -554,6 +554,7 @@ u: User
def f() -> str: ...
'{[f()]}'.format(u) # E: Invalid index expression in format field accessor "[f()]"
[builtins fixtures/primitives.pyi]
[typing fixtures/typing-typeddict.pyi]

[case testFormatCallFlags]
from typing import Union
Expand Down
7 changes: 3 additions & 4 deletions test-data/unit/check-functions.test
Original file line number Diff line number Diff line change
Expand Up @@ -3399,8 +3399,7 @@ class Bar(Foo):
[builtins fixtures/property.pyi]

[case testNoCrashOnUnpackOverride]
from typing import Unpack
from typing_extensions import TypedDict
from typing import TypedDict, Unpack

class Params(TypedDict):
x: int
Expand All @@ -3419,9 +3418,9 @@ class C(B):
# N: def meth(*, x: int, y: str) -> None \
# N: Subclass: \
# N: def meth(*, x: int, y: int) -> None

...
[builtins fixtures/tuple.pyi]
[builtins fixtures/dict.pyi]
[typing fixtures/typing-full.pyi]

[case testOverrideErrorLocationNamed]
class B:
Expand Down
5 changes: 3 additions & 2 deletions test-data/unit/check-functools.test
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,8 @@ def foo(cls3: Type[B[T]]):
[builtins fixtures/tuple.pyi]

[case testFunctoolsPartialTypedDictUnpack]
from typing_extensions import TypedDict, Unpack
from typing import TypedDict
from typing_extensions import Unpack
from functools import partial

class D1(TypedDict, total=False):
Expand Down Expand Up @@ -509,8 +510,8 @@ def main6(a2good: A2Good, a2bad: A2Bad, **d1: Unpack[D1]) -> None:
partial(fn4, **d1)(a2="asdf")
partial(fn4, **d1)(**a2good)
partial(fn4, **d1)(**a2bad) # E: Argument "a2" to "fn4" has incompatible type "int"; expected "str"

[builtins fixtures/dict.pyi]
[typing fixtures/typing-typeddict.pyi]


[case testFunctoolsPartialNestedGeneric]
Expand Down
25 changes: 16 additions & 9 deletions test-data/unit/check-incremental.test
Original file line number Diff line number Diff line change
Expand Up @@ -5740,8 +5740,8 @@ import b
b.xyz

[file b.py]
from typing import NamedTuple, NewType
from typing_extensions import TypedDict, TypeAlias
from typing import NamedTuple, NewType, TypedDict
from typing_extensions import TypeAlias
from enum import Enum
from dataclasses import dataclass

Expand Down Expand Up @@ -5777,6 +5777,7 @@ class C:
n: N = N(NT1(c=1))

[builtins fixtures/dict.pyi]
[typing fixtures/typing-typeddict.pyi]
[out2]
tmp/a.py:2: error: "object" has no attribute "xyz"

Expand Down Expand Up @@ -6079,7 +6080,8 @@ tmp/b.py:3: error: Incompatible types in assignment (expression has type "int",
[case testUnpackKwargsSerialize]
import m
[file lib.py]
from typing_extensions import Unpack, TypedDict
from typing import TypedDict
from typing_extensions import Unpack

class Person(TypedDict):
name: str
Expand All @@ -6095,6 +6097,7 @@ foo(name='Jennifer', age=38)
from lib import foo
foo(name='Jennifer', age="38")
[builtins fixtures/dict.pyi]
[typing fixtures/typing-typeddict.pyi]
[out]
[out2]
tmp/m.py:2: error: Argument "age" to "foo" has incompatible type "str"; expected "int"
Expand Down Expand Up @@ -6276,7 +6279,7 @@ import f
# modify

[file f.py]
from typing_extensions import TypedDict
from typing import TypedDict
import c
class D(TypedDict):
x: c.C
Expand All @@ -6297,6 +6300,7 @@ class C: ...
class C: ...
[file pb1.py.2]
[builtins fixtures/dict.pyi]
[typing fixtures/typing-typeddict.pyi]
[out]
[out2]
[out3]
Expand Down Expand Up @@ -6464,8 +6468,7 @@ y: int = x
[case testGenericTypedDictWithError]
import b
[file a.py]
from typing import Generic, TypeVar
from typing_extensions import TypedDict
from typing import Generic, TypeVar, TypedDict

TValue = TypeVar("TValue")
class Dict(TypedDict, Generic[TValue]):
Expand All @@ -6487,6 +6490,7 @@ def f(d: Dict[TValue]) -> TValue:
def g(d: Dict[TValue]) -> TValue:
return d["y"]
[builtins fixtures/dict.pyi]
[typing fixtures/typing-typeddict.pyi]
[out]
tmp/b.py:6: error: TypedDict "a.Dict[TValue]" has no key "x"
[out2]
Expand Down Expand Up @@ -6588,9 +6592,10 @@ import counts
import counts
# touch
[file counts.py]
from typing_extensions import TypedDict
from typing import TypedDict
Counts = TypedDict("Counts", {k: int for k in "abc"}) # type: ignore
[builtins fixtures/dict.pyi]
[typing fixtures/typing-typeddict.pyi]

[case testNoIncrementalCrashOnInvalidTypedDictFunc]
import m
Expand All @@ -6600,10 +6605,11 @@ import counts
import counts
# touch
[file counts.py]
from typing_extensions import TypedDict
from typing import TypedDict
def test() -> None:
Counts = TypedDict("Counts", {k: int for k in "abc"}) # type: ignore
[builtins fixtures/dict.pyi]
[typing fixtures/typing-typeddict.pyi]

[case testNoIncrementalCrashOnTypedDictMethod]
import a
Expand All @@ -6615,13 +6621,14 @@ from b import C
x: C
reveal_type(x.h)
[file b.py]
from typing_extensions import TypedDict
from typing import TypedDict
class C:
def __init__(self) -> None:
self.h: Hidden
class Hidden(TypedDict):
x: int
[builtins fixtures/dict.pyi]
[typing fixtures/typing-typeddict.pyi]
[out]
[out2]
tmp/a.py:3: note: Revealed type is "TypedDict('b.C.Hidden@5', {'x': builtins.int})"
Expand Down
3 changes: 2 additions & 1 deletion test-data/unit/check-inference.test
Original file line number Diff line number Diff line change
Expand Up @@ -1239,7 +1239,7 @@ class B: pass
[out]

[case testForStatementIndexNarrowing]
from typing_extensions import TypedDict
from typing import TypedDict

class X(TypedDict):
hourly: int
Expand All @@ -1266,6 +1266,7 @@ for b in ("hourly", "daily"):
reveal_type(b) # N: Revealed type is "builtins.str"
reveal_type(b.upper()) # N: Revealed type is "builtins.str"
[builtins fixtures/for.pyi]
[typing fixtures/typing-full.pyi]


-- Regression tests
Expand Down
Loading