forked from python/mypy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck-dataclass-transform.test
More file actions
46 lines (35 loc) · 1.22 KB
/
check-dataclass-transform.test
File metadata and controls
46 lines (35 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
[case testDataclassTransformReusesDataclassLogic]
# flags: --python-version 3.7
from typing import dataclass_transform, Type
@dataclass_transform()
def my_dataclass(cls: Type) -> Type:
return cls
@my_dataclass
class Person:
name: str
age: int
def summary(self):
return "%s is %d years old." % (self.name, self.age)
reveal_type(Person) # N: Revealed type is "def (name: builtins.str, age: builtins.int) -> __main__.Person"
Person('John', 32)
Person('Jonh', 21, None) # E: Too many arguments for "Person"
[typing fixtures/typing-medium.pyi]
[builtins fixtures/dataclasses.pyi]
[case testDataclassTransformIsFoundInTypingExtensions]
# flags: --python-version 3.7
from typing import Type
from typing_extensions import dataclass_transform
@dataclass_transform()
def my_dataclass(cls: Type) -> Type:
return cls
@my_dataclass
class Person:
name: str
age: int
def summary(self):
return "%s is %d years old." % (self.name, self.age)
reveal_type(Person) # N: Revealed type is "def (name: builtins.str, age: builtins.int) -> __main__.Person"
Person('John', 32)
Person('Jonh', 21, None) # E: Too many arguments for "Person"
[typing fixtures/typing-full.pyi]
[builtins fixtures/dataclasses.pyi]