Skip to content
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

Constrain multiple BaseModelAdmin attributes to be either list or tuple #1832

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions django-stubs/contrib/admin/options.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,19 @@ _ListFilterT: TypeAlias = (
_ModelT = TypeVar("_ModelT", bound=Model)

class BaseModelAdmin(Generic[_ModelT]):
autocomplete_fields: Sequence[str]
raw_id_fields: Sequence[str]
autocomplete_fields: _ListOrTuple[str]
raw_id_fields: _ListOrTuple[str]
fields: _FieldGroups | None
exclude: Sequence[str] | None
exclude: _ListOrTuple[str] | None
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we update the getter methods below as well, e.g. get_exclude(...) -> Sequence[str] to _ListOrTuple?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I'm not totally sure but it could probably be reasonable to align? I mean, per default these methods just do return self.<attribute>

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah my preference would be to update methods as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'll push a new PR with fixes very soon. Trying to check their alignment just now.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #1833

fieldsets: _FieldsetSpec | None
form: type[forms.ModelForm[_ModelT]]
filter_vertical: Sequence[str]
filter_horizontal: Sequence[str]
filter_vertical: _ListOrTuple[str]
filter_horizontal: _ListOrTuple[str]
radio_fields: Mapping[str, _Direction]
prepopulated_fields: dict[str, Sequence[str]]
formfield_overrides: Mapping[type[Field], Mapping[str, Any]]
readonly_fields: Sequence[str]
ordering: Sequence[str] | None
readonly_fields: _ListOrTuple[str] | None
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think readonly_fields is allowed to be None?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, nice find. This was a copy paste mistake..

ordering: _ListOrTuple[str] | None
sortable_by: _ListOrTuple[str] | None
view_on_site: bool | Callable[[_ModelT], str]
show_full_result_count: bool
Expand Down Expand Up @@ -136,19 +136,19 @@ class ModelAdmin(BaseModelAdmin[_ModelT]):
list_display: _DisplayT
list_display_links: _DisplayT | None
list_filter: _ListOrTuple[_ListFilterT]
list_select_related: bool | Sequence[str]
list_select_related: bool | _ListOrTuple[str]
list_per_page: int
list_max_show_all: int
list_editable: Sequence[str]
search_fields: Sequence[str]
list_editable: _ListOrTuple[str]
search_fields: _ListOrTuple[str]
search_help_text: _StrOrPromise | None
date_hierarchy: str | None
save_as: bool
save_as_continue: bool
save_on_top: bool
paginator: type
preserve_filters: bool
inlines: Sequence[type[InlineModelAdmin]]
inlines: _ListOrTuple[type[InlineModelAdmin]]
add_form_template: _TemplateForResponseT | None
change_form_template: _TemplateForResponseT | None
change_list_template: _TemplateForResponseT | None
Expand Down