Skip to content

Commit aaa99f8

Browse files
committed
Add test cases
1 parent c3e02f7 commit aaa99f8

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

test-data/unit/check-dataclasses.test

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2647,3 +2647,22 @@ User("", 0) # E: Too many positional arguments for "User"
26472647
User("", id=0)
26482648
User("", name="") # E: "User" gets multiple values for keyword argument "name"
26492649
[builtins fixtures/tuple.pyi]
2650+
2651+
[case testDataclassDefaultFactoryTypedDict]
2652+
from dataclasses import dataclass, field
2653+
from mypy_extensions import TypedDict
2654+
2655+
class Person(TypedDict, total=False):
2656+
name: str
2657+
2658+
@dataclass
2659+
class Job:
2660+
person: Person = field(default_factory=Person)
2661+
2662+
class PersonBad(TypedDict):
2663+
name: str
2664+
2665+
@dataclass
2666+
class JobBad:
2667+
person: PersonBad = field(default_factory=PersonBad) # E: Argument "default_factory" to "field" has incompatible type "type[PersonBad]"; expected "Callable[[], PersonBad]"
2668+
[builtins fixtures/dict.pyi]

test-data/unit/check-typeddict.test

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4258,3 +4258,17 @@ e1: E = {"x": 0, "y": "a"}
42584258
e2: E = {"x": "no", "y": "a"}
42594259
[builtins fixtures/dict.pyi]
42604260
[typing fixtures/typing-typeddict.pyi]
4261+
4262+
[case testTypedDictAliasAsInstanceAttribute]
4263+
from typing import TypedDict
4264+
4265+
class Dicts:
4266+
class TF(TypedDict, total=False):
4267+
user_id: int
4268+
TotalFalse = TF
4269+
4270+
dicts = Dicts()
4271+
reveal_type(dicts.TF) # N: Revealed type is "def (*, user_id: builtins.int =) -> TypedDict('__main__.Dicts.TF', {'user_id'?: builtins.int})"
4272+
reveal_type(dicts.TotalFalse) # N: Revealed type is "def (*, user_id: builtins.int =) -> TypedDict('__main__.Dicts.TF', {'user_id'?: builtins.int})"
4273+
[builtins fixtures/dict.pyi]
4274+
[typing fixtures/typing-typeddict.pyi]

0 commit comments

Comments
 (0)