Skip to content

[django-filter] Replace list with more generic Sequence #14567

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

Merged

Conversation

H4rryK4ne
Copy link
Contributor

for FilterSetOptions and filterset_factory

fixes #14565

for FilterSetOptions and filterset_factory
@H4rryK4ne H4rryK4ne changed the title Replace list with more generic Collection [django-filter] Replace list with more generic Collection Aug 12, 2025

This comment has been minimized.

@H4rryK4ne
Copy link
Contributor Author

@huynguyengl99 @intgr Maybe you can review this PR

Comment on lines 22 to 23
fields: Collection[str] | dict[str, Collection[str]] | str | None
exclude: Collection[str] | None
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we use Iterable instead of Collection here? I think we just need to iterate over the fields, so Iterable might be a better choice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

At least for exclude there is a __contains__ check (django_filters.filterset.BaseFilterSet.get_fields L305)). Therefore I switched to Collection.

Also, if one uses an iterator/generator, this may break things since it runs just once.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, I checked djangorestframework-stubs, and it looks like the package mainly uses Sequence and does not use Collection anywhere. I think it would be better to use Sequence to follow the current usage in Django REST framework.

@huynguyengl99
Copy link
Contributor

@H4rryK4ne Oh, sorry — I had already reviewed it but forgot to press Submit 😂

@H4rryK4ne H4rryK4ne changed the title [django-filter] Replace list with more generic Collection [django-filter] Replace list with more generic Sequence Aug 14, 2025
Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

Copy link
Contributor

@intgr intgr left a comment

Choose a reason for hiding this comment

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

Looks good to me

@srittau srittau merged commit 1455669 into python:main Aug 14, 2025
48 checks passed
@H4rryK4ne H4rryK4ne deleted the django-filter/replace_list_with_colleciton branch August 14, 2025 19:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[django-filter] Generic iterables to use tuples instead of lists
4 participants