Skip to content

Commit

Permalink
Improve forms stubs (#862)
Browse files Browse the repository at this point in the history
* `default_renderer` may be a renderer class, instance, or `None`: https://docs.djangoproject.com/en/4.0/ref/forms/api/#django.forms.Form.default_renderer
* `field_order` should be a list/sequence of field names, or `None`: https://docs.djangoproject.com/en/4.0/ref/forms/api/#django.forms.Form.field_order
* `cleaned_data` should be a dict/mapping of field names to values, as returned by `clean()`: https://docs.djangoproject.com/en/4.0/ref/forms/api/#django.forms.Form.cleaned_data . I similarly updated `clean()` to allow arbitrary mappings, since it may be legitimate to use some special mapping class.
* `clean()` does not need to return a mapping - https://docs.djangoproject.com/en/4.0/ref/forms/validation/#validating-fields-with-clean : “If your form inherits another that doesn’t return a `cleaned_data` dictionary in its `clean()` method (doing so is optional)...”
* `is_multipart` returns a `bool`: https://docs.djangoproject.com/en/4.0/ref/forms/api/#django.forms.Form.is_multipart
* `hidden_fields` and `visible_fields` aren't documented, but they return lists of `BoundField` instances: https://github.com/django/django/blob/d8b437b1fbe3bf54822833bea5e19d2142cf3e1f/django/forms/forms.py#L501-L513
  • Loading branch information
adamchainz authored Mar 2, 2022
1 parent 078925a commit eb6991b
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions django-stubs/forms/forms.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class DeclarativeFieldsMetaclass(MediaDefiningClass): ...
class BaseForm:
class Meta:
fields: Sequence[str] = ...
default_renderer: Any = ...
field_order: Any = ...
default_renderer: Union[None, BaseRenderer, type[BaseRenderer]] = ...
field_order: Optional[Sequence[str]] = ...
use_required_attribute: bool = ...
is_bound: bool = ...
data: Dict[str, Any] = ...
Expand All @@ -29,7 +29,7 @@ class BaseForm:
empty_permitted: bool = ...
fields: Dict[str, Any] = ...
renderer: BaseRenderer = ...
cleaned_data: Any = ...
cleaned_data: Mapping[str, Any] = ...
def __init__(
self,
data: Optional[Mapping[str, Any]] = ...,
Expand Down Expand Up @@ -59,15 +59,15 @@ class BaseForm:
def add_error(self, field: Optional[str], error: Union[ValidationError, str]) -> None: ...
def has_error(self, field: Any, code: Optional[Any] = ...): ...
def full_clean(self) -> None: ...
def clean(self) -> Dict[str, Any]: ...
def clean(self) -> Optional[Mapping[str, Any]]: ...
def has_changed(self) -> bool: ...
@property
def changed_data(self) -> List[str]: ...
@property
def media(self) -> Media: ...
def is_multipart(self): ...
def hidden_fields(self): ...
def visible_fields(self): ...
def is_multipart(self) -> bool: ...
def hidden_fields(self) -> List[BoundField]: ...
def visible_fields(self) -> List[BoundField]: ...
def get_initial_for_field(self, field: Field, field_name: str) -> Any: ...
def _html_output(
self,
Expand Down

0 comments on commit eb6991b

Please sign in to comment.