|
18 | 18 | reveal_type(user.my_custom_field13) # N: Revealed type is "Union[myapp.models.CustomFieldValue, None]"
|
19 | 19 | reveal_type(user.my_custom_field14) # N: Revealed type is "Union[builtins.bool, None]"
|
20 | 20 | reveal_type(user.my_custom_field15) # N: Revealed type is "None"
|
| 21 | +
|
| 22 | + reveal_type(user.my_custom_field_any1) # N: Revealed type is "Any" |
| 23 | + reveal_type(user.my_custom_field_any2) # N: Revealed type is "Any" |
| 24 | + reveal_type(user.my_custom_field_any3) # N: Revealed type is "Any" |
| 25 | + reveal_type(user.my_custom_field_any4) # N: Revealed type is "Any" |
21 | 26 | monkeypatch: true
|
22 |
| - out: | |
23 |
| - myapp/models:31: error: GenericField is nullable but its generic get type parameter is not optional [misc] |
24 |
| - myapp/models:32: error: CustomValueField is nullable but its generic get type parameter is not optional [misc] |
25 |
| - myapp/models:33: error: SingleTypeField is nullable but its generic get type parameter is not optional [misc] |
26 |
| - myapp/models:34: error: AdditionalTypeVarField is nullable but its generic get type parameter is not optional [misc] |
27 |
| - myapp/models:35: error: Field is nullable but its generic get type parameter is not optional [misc] |
28 | 27 | installed_apps:
|
29 | 28 | - myapp
|
30 | 29 | files:
|
|
53 | 52 |
|
54 | 53 | class CustomSmallIntegerField(fields.SmallIntegerField[_ST, _GT]): ...
|
55 | 54 |
|
| 55 | + class FieldImplicitAny(fields.Field): ... |
| 56 | + class FieldExplicitAny(fields.Field[Any, Any]): ... |
| 57 | +
|
56 | 58 | class User(models.Model):
|
57 | 59 | id = models.AutoField(primary_key=True)
|
58 | 60 | my_custom_field1 = GenericField[Union[CustomFieldValue, int], CustomFieldValue]()
|
59 | 61 | my_custom_field2 = CustomValueField()
|
60 | 62 | my_custom_field3 = SingleTypeField[bool]()
|
61 | 63 | my_custom_field4 = AdditionalTypeVarField[Union[CustomFieldValue, int], CustomFieldValue, bool]()
|
| 64 | + my_custom_field_any1 = FieldImplicitAny() |
| 65 | + my_custom_field_any2 = FieldExplicitAny() |
62 | 66 |
|
63 | 67 | # test null=True on fields with non-optional generic types throw error
|
64 |
| - my_custom_field5 = GenericField[Union[CustomFieldValue, int], CustomFieldValue](null=True) |
65 |
| - my_custom_field6 = CustomValueField(null=True) |
66 |
| - my_custom_field7 = SingleTypeField[bool](null=True) |
67 |
| - my_custom_field8 = AdditionalTypeVarField[Union[CustomFieldValue, int], CustomFieldValue, bool](null=True) |
68 |
| - my_custom_field9 = fields.Field[Union[CustomFieldValue, int], CustomFieldValue](null=True) |
| 68 | + my_custom_field5 = GenericField[Union[CustomFieldValue, int], CustomFieldValue](null=True) # E: GenericField is nullable but its generic get type parameter is not optional [misc] |
| 69 | + my_custom_field6 = CustomValueField(null=True) # E: CustomValueField is nullable but its generic get type parameter is not optional [misc] |
| 70 | + my_custom_field7 = SingleTypeField[bool](null=True) # E: SingleTypeField is nullable but its generic get type parameter is not optional [misc] |
| 71 | + my_custom_field8 = AdditionalTypeVarField[Union[CustomFieldValue, int], CustomFieldValue, bool](null=True) # E: AdditionalTypeVarField is nullable but its generic get type parameter is not optional [misc] |
| 72 | + my_custom_field9 = fields.Field[Union[CustomFieldValue, int], CustomFieldValue](null=True) # E: Field is nullable but its generic get type parameter is not optional [misc] |
69 | 73 |
|
70 | 74 | # test overriding fields that set _pyi_private_set_type or _pyi_private_get_type
|
71 | 75 | my_custom_field10 = fields.SmallIntegerField[bool, bool]()
|
|
76 | 80 | my_custom_field13 = GenericField[Union[CustomFieldValue, int], Union[CustomFieldValue, None]](null=True)
|
77 | 81 | my_custom_field14 = SingleTypeField[Union[bool, None]](null=True)
|
78 | 82 | my_custom_field15 = fields.Field[None, None](null=True)
|
| 83 | +
|
| 84 | + # test null=True on Any does not raise |
| 85 | + my_custom_field_any3 = FieldImplicitAny(null=True) |
| 86 | + my_custom_field_any4 = FieldExplicitAny(null=True) |
0 commit comments