Skip to content

[django-filter] Mark to_html, BaseCSVWidget.value_from_datadict and filter_for_lookup as possibly None - #16877

Open
ArnabDutta01 wants to merge 1 commit into
python:mainfrom
ArnabDutta01:fix/django-filter-optional-returns
Open

ArnabDutta01 wants to merge 1 commit into
python:mainfrom
ArnabDutta01:fix/django-filter-optional-returns

Conversation

@ArnabDutta01

Copy link
Copy Markdown
Contributor

Three return types leave out None although the runtime returns it in common cases:

  • DjangoFilterBackend.to_html() returns None when the view has no filterset (it returns early when get_filterset() is None, which the stub already marks as optional).
  • BaseCSVWidget.value_from_datadict() returns None when the field is missing from the data. QueryArrayWidget always returns a list, so its override stays list[str].
  • BaseFilterSet.filter_for_lookup() returns (None, {}) for field types it can't map; filter_for_field() checks for that before calling handle_unrecognized_field().
>>> CSVWidget().value_from_datadict({}, {}, "x")
None
>>> DjangoFilterBackend().to_html(request, User.objects.all(), view_without_filterset)
None
>>> FilterSet.filter_for_lookup(models.BinaryField(), "exact")
(None, {})

@github-actions

Copy link
Copy Markdown
Contributor

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

This branch has not been deployed

No deployments
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.

1 participant