Changes between Version 2 and Version 3 of Ticket #35731, comment 5
- Timestamp:
- Sep 5, 2024, 2:36:44 PM (3 months ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #35731, comment 5
v2 v3 20 20 > If default is passed to the field, then val has a type of int. If it's not, then its type is int | None. In my proposal above, passing db_default wouldn't change the type of foo, whereas the current implementation means its type is int | DatabaseDefault, int | None, or int, depending on what combo of default and db_default is passed. 21 21 22 That's a bad assumption unfortunately, every property associated with a field are `| Expression[F]` where `F` is bound to the field type and represents its `output_field` . In other words, `IntegerField(null=True)` results in a descriptor that is `int | None | Expression[IntegerField]` and not simply `int | None`.22 That's a bad assumption unfortunately, every property associated with a field are `| Expression[F]` where `F` is bound to the field type and represents its `output_field` and `Expression` is a protocol identifiable by `callable(getattr(type, "resolve_expression", None))`. In other words, `IntegerField(null=True)` results in a descriptor that is `int | None | Expression[IntegerField]` and not simply `int | None`. I know a few typing library simply this edge case but its pretty much an allowed assignment type.