Skip to content

[django-filter] Improve constructor param types and add missing re-exports - #14556

Merged
srittau merged 1 commit into
python:mainfrom
intgr:improve-django-filter
Aug 14, 2025
Merged

srittau merged 1 commit into
python:mainfrom
intgr:improve-django-filter

Conversation

@intgr

@intgr intgr commented Aug 10, 2025 •

Copy link
Copy Markdown
Contributor

This is all I found that could be improved in #14540. FYI @huynguyengl99

  • Accept StrOrPromise for field labels -- allow Django lazy translated strings.
  • Added __init__ params that are inherited from parent classes. Reduced usage of loosely typed *args, **kwargs.
  • Removed __init__ method type hints from classes whose parameters are same as parent class -- to avoid duplicating them.
  • Added missing re-exports to django_filters/rest_framework/__init__.pyi -- the imports in this file are clearly meant as re-export

@github-actions

This comment has been minimized.

@donbarbos

Copy link
Copy Markdown
Contributor

Just a quick note — it’s generally a good practice to add a comment for each use of Any. If you’re unsure whether it should be Any, it might be better to use Incomplete instead.
It’s also important to ensure that the stubtests are passing. And regarding __all__ in type stubs - it should simply reflect the real __all__ in the source code, and it’s worth including it in the stubs if it exists in the source.

@srittau srittau left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM, but one question below.

Comment thread stubs/django-filter/django_filters/fields.pyi
@intgr

intgr commented Aug 11, 2025 •

Copy link
Copy Markdown
Contributor Author

Thanks, I'll find the time some day to fix CI errors and resolve review comments.

__all__ in type stubs - it should simply reflect the real __all__ in the source code

👍 I will convert them to import X as X imports.

@intgr intgr changed the title [django-filter] Improve constructor param types and add missing __all__ [django-filter] Improve constructor param types and add missing re-exports Aug 12, 2025
@intgr
intgr force-pushed the improve-django-filter branch from 63a8427 to 5ca265b Compare August 12, 2025 21:05
@github-actions

This comment has been minimized.

…ports

* Accept `StrOrPromise` for field labels -- allow Django lazy translated strings.
* Added `__init__` params that are inherited from parent classes. Reduced usage of loosely typed `*args, **kwargs`.
* Removed `__init__` method type hints from classes whose parameters are same as parent class -- to avoid duplicating them.
* Added missing re-exports to `django_filters/rest_framework/__init__.pyi` -- the imports in this file are clearly meant as re-export
@intgr
intgr force-pushed the improve-django-filter branch from 5ca265b to 014fff7 Compare August 14, 2025 17:26
@github-actions

Copy link
Copy Markdown
Contributor

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

@intgr

intgr commented Aug 14, 2025

Copy link
Copy Markdown
Contributor Author

Tests fixed -- restored the _ChoicesInput I copied from django-stubs (and other aliases referenced by _ChoicesInput)

@srittau
srittau merged commit 893b9a7 into python:main Aug 14, 2025
@intgr
intgr deleted the improve-django-filter branch August 14, 2025 19:01
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.

3 participants