|
48 | 48 | - case: default_and_inital_args_fields |
49 | 49 | main: | |
50 | 50 | from rest_framework.fields import DictField, CharField, empty |
51 | | - from typing import Optional, Dict, Any |
| 51 | + from typing import Dict, Any |
52 | 52 |
|
53 | 53 | CharField(initial='', default=lambda: '') |
54 | | - CharField(initial=None, default=4) # E: Argument "default" to "CharField" has incompatible type "int"; expected "Union[Union[str, _StrPromise], Callable[[], Union[str, _StrPromise]], _Empty, None]" |
55 | | - CharField(initial={}, default=empty) # E: Argument "initial" to "CharField" has incompatible type "dict[Never, Never]"; expected "Union[str, Callable[[], str], _Empty, None]" |
| 54 | + CharField(initial=None, default=4) # E: Argument "default" to "CharField" has incompatible type "int"; expected "str | _StrPromise | Callable[[], str | _StrPromise] | _Empty | None" |
| 55 | + CharField(initial={}, default=empty) # E: Argument "initial" to "CharField" has incompatible type "dict[Never, Never]"; expected "str | Callable[[], str] | _Empty | None" |
56 | 56 |
|
57 | | - x: Optional[str] = CharField().get_initial() |
58 | | - y: Optional[int] = CharField().get_initial() # E: Incompatible types in assignment (expression has type "Optional[str]", variable has type "Optional[int]") |
| 57 | + x: str | None = CharField().get_initial() |
| 58 | + y: int | None = CharField().get_initial() # E: Incompatible types in assignment (expression has type "str | None", variable has type "int | None") |
59 | 59 |
|
60 | 60 | - case: float_field_args_fields |
61 | 61 | main: | |
|
66 | 66 |
|
67 | 67 | - case: ChoiceField_default |
68 | 68 | main: | |
69 | | - from typing import Union |
70 | 69 | from rest_framework.fields import ChoiceField |
71 | 70 |
|
72 | 71 | def int_callback() -> int: ... |
73 | | - def mixed_callback() -> Union[int, str]: ... |
| 72 | + def mixed_callback() -> int | str: ... |
74 | 73 |
|
75 | 74 | ChoiceField([1], default=1) |
76 | 75 | ChoiceField(['test'], allow_null=True, default=None) |
77 | 76 | ChoiceField([1], default=int_callback) |
78 | 77 | ChoiceField([1, 'lulz'], default=mixed_callback) |
79 | | - ChoiceField([1], default=lambda: None) # E: Argument "default" to "ChoiceField" has incompatible type "Callable[[], None]"; expected "Union[Union[str, _StrPromise], int, Callable[[], Union[Union[str, _StrPromise], int]], _Empty, None]" # E: Incompatible return value type (got "None", expected "Union[Union[str, _StrPromise], int]") |
| 78 | + ChoiceField([1], default=lambda: None) # E: Argument "default" to "ChoiceField" has incompatible type "Callable[[], None]"; expected "str | _StrPromise | int | Callable[[], str | _StrPromise | int] | _Empty | None" # E: Incompatible return value type (got "None", expected "str | _StrPromise | int") |
80 | 79 |
|
81 | 80 | - case: MultipleChoiceField_default |
82 | 81 | main: | |
83 | | - from typing import Union |
84 | 82 | from rest_framework.fields import MultipleChoiceField |
85 | 83 |
|
86 | 84 | def int_set_callback() -> set[int]: ... |
87 | | - def mixed_set_callback() -> set[Union[int, str]]: ... |
| 85 | + def mixed_set_callback() -> set[int | str]: ... |
88 | 86 |
|
89 | 87 | MultipleChoiceField(choices=[1], default={1}) |
90 | 88 | MultipleChoiceField(choices=['test'], allow_null=True, default=None) |
91 | 89 | MultipleChoiceField(choices=[1], default=int_set_callback) |
92 | 90 | MultipleChoiceField(choices=[1, 'lulz'], default=mixed_set_callback) |
93 | | - MultipleChoiceField(choices=[1], default=lambda: [1]) # E: Argument "default" to "MultipleChoiceField" has incompatible type "Callable[[], list[int]]"; expected "Union[set[Union[str, int]], set[str], set[int], Callable[[], Union[set[Union[str, int]], set[str], set[int]]], _Empty, None]" # E: Incompatible return value type (got "list[int]", expected "Union[set[Union[str, int]], set[str], set[int]]") |
| 91 | + MultipleChoiceField(choices=[1], default=lambda: [1]) # E: Argument "default" to "MultipleChoiceField" has incompatible type "Callable[[], list[int]]"; expected "set[str | int] | set[str] | set[int] | Callable[[], set[str | int] | set[str] | set[int]] | _Empty | None" # E: Incompatible return value type (got "list[int]", expected "set[str | int] | set[str] | set[int]") |
94 | 92 |
|
95 | 93 | MultipleChoiceField(choices=[(1, "1"), (2, "2")], default={1}) |
96 | | - MultipleChoiceField(choices=[(1, "1"), (2, "2")], default=[1]) # E: Argument "default" to "MultipleChoiceField" has incompatible type "list[int]"; expected "Union[set[Union[str, int]], set[str], set[int], Callable[[], Union[set[Union[str, int]], set[str], set[int]]], _Empty, None]" |
| 94 | + MultipleChoiceField(choices=[(1, "1"), (2, "2")], default=[1]) # E: Argument "default" to "MultipleChoiceField" has incompatible type "list[int]"; expected "set[str | int] | set[str] | set[int] | Callable[[], set[str | int] | set[str] | set[int]] | _Empty | None" |
97 | 95 |
|
98 | 96 | MultipleChoiceField(choices=[(1, "1"), (2, "2")], initial={1}) |
99 | | - MultipleChoiceField(choices=[(1, "1"), (2, "2")], initial=[1]) # E: Argument "initial" to "MultipleChoiceField" has incompatible type "list[int]"; expected "Union[set[Union[Union[str, _StrPromise], int]], set[Union[str, _StrPromise]], set[int], Callable[[], Union[set[Union[Union[str, _StrPromise], int]], set[Union[str, _StrPromise]], set[int]]], _Empty, None]" |
| 97 | + MultipleChoiceField(choices=[(1, "1"), (2, "2")], initial=[1]) # E: Argument "initial" to "MultipleChoiceField" has incompatible type "list[int]"; expected "set[str | _StrPromise | int] | set[str | _StrPromise] | set[int] | Callable[[], set[str | _StrPromise | int] | set[str | _StrPromise] | set[int]] | _Empty | None" |
100 | 98 |
|
101 | 99 | - case: FileField_default |
102 | 100 | main: | |
|
108 | 106 | FileField(allow_null=True, default=None) |
109 | 107 | FileField(allow_null=True, default=file_callback) |
110 | 108 | FileField(allow_null=True, default=file_callback()) |
111 | | - FileField(allow_null=True, default=123) # E: Argument "default" to "FileField" has incompatible type "int"; expected "Union[File[Any], Callable[[], File[Any]], _Empty, None]" |
| 109 | + FileField(allow_null=True, default=123) # E: Argument "default" to "FileField" has incompatible type "int"; expected "File[Any] | Callable[[], File[Any]] | _Empty | None" |
112 | 110 |
|
113 | 111 | ImageField(allow_null=True, default=None) |
114 | 112 | ImageField(default=file_callback) |
115 | 113 | ImageField(default=file_callback()) |
116 | | - ImageField(default='a') # E: Argument "default" to "ImageField" has incompatible type "str"; expected "Union[File[Any], Callable[[], File[Any]], _Empty, None]" |
| 114 | + ImageField(default='a') # E: Argument "default" to "ImageField" has incompatible type "str"; expected "File[Any] | Callable[[], File[Any]] | _Empty | None" |
117 | 115 |
|
118 | 116 | - case: DictField_default |
119 | 117 | main: | |
|
123 | 121 | DictField(default={}) |
124 | 122 | DictField(default={'a': 1, 'b': 2}) |
125 | 123 | DictField(default=lambda: {'a': [], 'b': 'str'}) |
126 | | - DictField(default=[]) # E: Argument "default" to "DictField" has incompatible type "list[Never]"; expected "Union[dict[Any, Any], Callable[[], dict[Any, Any]], _Empty, None]" |
| 124 | + DictField(default=[]) # E: Argument "default" to "DictField" has incompatible type "list[Never]"; expected "dict[Any, Any] | Callable[[], dict[Any, Any]] | _Empty | None" |
127 | 125 |
|
128 | 126 | JSONField(allow_null=True, default=None) |
129 | 127 | JSONField(default={}) |
130 | 128 | JSONField(default={'a': 1, 'b': 2}) |
131 | 129 | JSONField(default=lambda: {'a': [], 'b': 'str'}) |
132 | | - JSONField(default=[]) # E: Argument "default" to "JSONField" has incompatible type "list[Never]"; expected "Union[Mapping[Any, Any], Callable[[], Mapping[Any, Any]], _Empty, None]" |
| 130 | + JSONField(default=[]) # E: Argument "default" to "JSONField" has incompatible type "list[Never]"; expected "Mapping[Any, Any] | Callable[[], Mapping[Any, Any]] | _Empty | None" |
133 | 131 |
|
134 | 132 | - case: ListField_default |
135 | 133 | main: | |
|
139 | 137 | ListField(default=[]) |
140 | 138 | ListField(default=[0, 'one']) |
141 | 139 | ListField(default=lambda: []) |
142 | | - ListField(default='wät') # E: Argument "default" to "ListField" has incompatible type "str"; expected "Union[list[Any], Callable[[], list[Any]], _Empty, None]" |
| 140 | + ListField(default='wät') # E: Argument "default" to "ListField" has incompatible type "str"; expected "list[Any] | Callable[[], list[Any]] | _Empty | None" |
0 commit comments