Skip to content

[django-filter] Mark always-set FilterSet and OrderingFilter attributes non-optional - #16712

Merged
srittau merged 1 commit into
python:mainfrom
vintitres:django-filter-non-optional
Nov 6, 2026
Merged

srittau merged 1 commit into
python:mainfrom
vintitres:django-filter-non-optional

Conversation

@vintitres

Copy link
Copy Markdown
Contributor

These attributes are always set in __init__, so they are never None at runtime:

  • BaseFilterSet.data: self.data = data or QueryDict()
  • BaseFilterSet.queryset: falls back to self._meta.model._default_manager.all() when queryset is None
  • OrderingFilter.param_map: self.param_map = {v: k for k, v in fields.items()} (and filter() calls self.param_map.get(...) unguarded)

The __init__ parameters stay optional. Today callers have to write things like (filterset.data or {}).get(...) to satisfy the type checker.

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

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

@srittau
srittau merged commit 79a3f6c into python:main Nov 6, 2026
74 checks passed
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.

2 participants