mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-10 22:11:54 +08:00
Improve forms stubs (#862)
* `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: d8b437b1fb/django/forms/forms.py (L501-L513)
This commit is contained in:
@@ -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] = ...
|
||||
@@ -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]] = ...,
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user