forked from typeddjango/django-stubs
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Forms and exceptions improvements (#259)
- Removed some unnecessary `= ...` on class attributes ([see typing docs](https://typing.readthedocs.io/en/latest/guides/writing_stubs.html#classes)) - Added new exceptions to `django.core.exceptions` - Added more specific types to `ValidationError` - Gave `BaseForm` its parent class and made **`BaseForm.fields` more specific** - Moved the `_meta` attribute from `BaseForm` to `ModelForm` - Gave `Form` its metaclass and marked its attributes as class variables - Improved type for `ModelFormOptions.formfield_callback` - `forms.utils`: Added new classes, polished types on existing ones
- Loading branch information
1 parent
8a8a805
commit 84064af
Showing
4 changed files
with
94 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,61 @@ | ||
from collections import UserList | ||
from collections.abc import Sequence | ||
from collections.abc import Mapping, Sequence | ||
from datetime import datetime | ||
from typing import Any | ||
|
||
from django.core.exceptions import ValidationError | ||
from django.forms.renderers import BaseRenderer | ||
from django.utils.safestring import SafeText | ||
|
||
def pretty_name(name: str) -> str: ... | ||
def flatatt(attrs: dict[str, Any]) -> SafeText: ... | ||
|
||
class ErrorDict(dict[str, Any]): | ||
class RenderableMixin: | ||
def get_context(self) -> Mapping[str, Any]: ... | ||
def render( | ||
self, | ||
template_name: str | None = ..., | ||
context: Mapping[str, Any] | None = ..., | ||
renderer: BaseRenderer | None = ..., | ||
) -> SafeText: ... | ||
|
||
class RenderableFormMixin(RenderableMixin): | ||
def as_p(self) -> SafeText: ... | ||
def as_table(self) -> SafeText: ... | ||
def as_ul(self) -> SafeText: ... | ||
def as_div(self) -> SafeText: ... | ||
|
||
class RenderableErrorMixin(RenderableMixin): | ||
def as_json(self, escape_html: bool = ...) -> str: ... | ||
def as_text(self) -> SafeText: ... | ||
def as_ul(self) -> SafeText: ... | ||
|
||
class ErrorDict(dict[str, ErrorList], RenderableErrorMixin): | ||
template_name: str | ||
template_name_text: str | ||
template_name_ul: str | ||
renderer: BaseRenderer | ||
def __init__( | ||
self, *args: Any, renderer: BaseRenderer | None = ..., **kwargs: Any | ||
): ... | ||
def as_data(self) -> dict[str, list[ValidationError]]: ... | ||
def get_json_data(self, escape_html: bool = ...) -> dict[str, Any]: ... | ||
def as_json(self, escape_html: bool = ...) -> str: ... | ||
def as_ul(self) -> str: ... | ||
def as_text(self) -> str: ... | ||
|
||
class ErrorList(UserList[Any]): | ||
class ErrorList(UserList[ValidationError | str], RenderableErrorMixin): | ||
template_name: str | ||
template_name_text: str | ||
template_name_ul: str | ||
data: list[ValidationError | str] | ||
error_class: str = ... | ||
error_class: str | ||
renderer: BaseRenderer | ||
def __init__( | ||
self, | ||
initlist: ErrorList | Sequence[str | Exception] | None = ..., | ||
initlist: Sequence[str | Exception] | None = ..., | ||
error_class: str | None = ..., | ||
renderer: BaseRenderer | None = None, | ||
) -> None: ... | ||
def as_data(self) -> list[ValidationError]: ... | ||
def get_json_data(self, escape_html: bool = ...) -> list[dict[str, str]]: ... | ||
def as_json(self, escape_html: bool = ...) -> str: ... | ||
def as_ul(self) -> str: ... | ||
def as_text(self) -> str: ... | ||
|
||
def from_current_timezone(value: datetime) -> datetime: ... | ||
def to_current_timezone(value: datetime) -> datetime: ... |