Skip to content

Add missing methods and fix inheritance in forms stubs#3153

Merged
sobolevn merged 1 commit intotypeddjango:masterfrom
emmanuel-ferdman:fix-forms-stubs
Mar 3, 2026
Merged

Add missing methods and fix inheritance in forms stubs#3153
sobolevn merged 1 commit intotypeddjango:masterfrom
emmanuel-ferdman:fix-forms-stubs

Conversation

@emmanuel-ferdman
Copy link
Copy Markdown
Contributor

PR Summary

This PR fixes forms module stubs to match runtime. It adds the missing __deepcopy__ methods to Field, ChoiceField, MultiValueField, and ModelChoiceField. It adds AltersData to the base classes of BaseModelForm and BaseModelFormSet so save_m2m is properly typed. It fixes BoundField.initial to use @cached_property instead of @property and adds __html__ to BoundWidget and Media. It corrects CheckboxSelectMultiple to inherit from RadioSelect like it does at runtime and moves id_for_label up to RadioSelect where it's actually defined. It removes phantom attributes that don't exist at runtime (HiddenInput.choices, RadioSelect.can_add_related, ErrorList.field_name) and fixes Input.input_type to be str | None since the base class has it as None. Also it exports ALL_FIELDS from django.forms, adds bound_field_class param to BaseForm.__init__, adds renderer param to formset_factory, and removes the bogus form_renderer/renderer params from BaseFormSet.__init__.

Final note: modelformset_factory and inlineformset_factory remain in the allowlist due to a stubtest false positive with type[TypeVar] params. I opened a PR to python/mypy#20950.

Signed-off-by: Emmanuel Ferdman <emmanuelferdman@gmail.com>
@sobolevn sobolevn merged commit da11939 into typeddjango:master Mar 3, 2026
54 checks passed
@emmanuel-ferdman emmanuel-ferdman deleted the fix-forms-stubs branch March 16, 2026 00:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants