-
-
Notifications
You must be signed in to change notification settings - Fork 456
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update models's fields' _Choices type #2476
base: master
Are you sure you want to change the base?
Conversation
django-stubs/utils/choices.pyi
Outdated
from typing import Any, Protocol, TypeVar, type_check_only | ||
|
||
from typing_extensions import TypeAlias | ||
|
||
_Choice: TypeAlias = tuple[Any, Any] | ||
_ChoiceNamedGroup: TypeAlias = tuple[str, Iterable[_Choice]] | ||
_Choices: TypeAlias = Iterable[_Choice | _ChoiceNamedGroup] | ||
_ChoicesMapping: TypeAlias = Mapping[Any, Any] | Mapping[str, Mapping[Any, Any]] # noqa: PYI047 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't it just Mapping[Any, Any]
?
@@ -0,0 +1,159 @@ | |||
- case: db_models_fields_choices |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tests/assert_type/db/models/fields/test_choices.py
test is enough, no need to duplicate it. Can you please test invalid types here? At least one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pushed an update now, was this what you had in mind?
8f89556
to
639c727
Compare
Django 5 allows model field choices to be callables, mappings or subclasses of models.Choices. This commit introduces these options in the stubs. Co-Authored-By: Stian Jensen <me@stianj.com>
c104ea7
to
3531bd4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Django 5 allows model field choices to be callables, mappings or subclasses of models.Choices. This commit introduces these options in the stubs.
Continuation of #2368, to fix a merge conflict, avoid issues with importing
Tuple
instead of usingtuple
, and avoid unnecessary formatting changes.