Change InlineModelAdmin.formset to Type[BaseInlineFormSet] (#521)

* Change InlineModelAdmin.formset to Type[BaseInlineFormSet]

* More exact annotations + add NaturalTimeFormatter

* Correction: cls type is Type[...]

* Complete annotations for PasswordResetTokenGenerator

* fix *gettext*_lazy annotations
This commit is contained in:
Robert Huselius
2020-11-06 09:04:34 +01:00
committed by GitHub
parent e837dac26a
commit a0d61c0de3
4 changed files with 27 additions and 9 deletions

View File

@@ -17,7 +17,7 @@ from typing import (
)
from django.forms.forms import BaseForm
from django.forms.formsets import BaseFormSet
from django.forms.models import BaseInlineFormSet
from typing_extensions import Literal, TypedDict
from django.contrib.admin.filters import ListFilter
@@ -268,7 +268,7 @@ class ModelAdmin(BaseModelAdmin[_ModelT]):
class InlineModelAdmin(BaseModelAdmin[_ModelT]):
model: Type[_ModelT] = ...
fk_name: str = ...
formset: BaseFormSet = ...
formset: Type[BaseInlineFormSet] = ...
extra: int = ...
min_num: Optional[int] = ...
max_num: Optional[int] = ...

View File

@@ -1,3 +1,4 @@
from datetime import date
from typing import Any, Optional
from django.contrib.auth.base_user import AbstractBaseUser
@@ -7,5 +8,10 @@ class PasswordResetTokenGenerator:
secret: Any = ...
def make_token(self, user: AbstractBaseUser) -> str: ...
def check_token(self, user: Optional[AbstractBaseUser], token: Optional[str]) -> bool: ...
def _make_token_with_timestamp(self, user: AbstractBaseUser, timestamp: int) -> str: ...
def _make_hash_value(self, user: AbstractBaseUser, timestamp: int) -> str: ...
def _num_days(self, dt: date) -> float: ...
def _today(self) -> date: ...
default_token_generator: Any

View File

@@ -1,14 +1,23 @@
from datetime import date, datetime as datetime
from typing import Any, Optional, SupportsInt, Union
from typing import Any, Callable, Dict, Optional, SupportsInt, Tuple, Type, Union
from django import template
register: Any
register: template.Library
def ordinal(value: Optional[Union[str, SupportsInt]]) -> Optional[str]: ...
def intcomma(value: Optional[Union[str, SupportsInt]], use_l10n: bool = ...) -> str: ...
intword_converters: Any
intword_converters: Tuple[Tuple[int, Callable]]
def intword(value: Optional[Union[str, SupportsInt]]) -> Optional[Union[int, str]]: ...
def apnumber(value: Optional[Union[str, SupportsInt]]) -> Optional[Union[int, str]]: ...
def naturalday(value: Optional[Union[date, str]], arg: None = ...) -> Optional[str]: ...
def naturaltime(value: datetime) -> str: ...
class NaturalTimeFormatter:
time_strings: Dict[str, str]
past_substrings: Dict[str, str]
future_substrings: Dict[str, str]
@classmethod
def string_for(cls: Type[NaturalTimeFormatter], value: Any) -> Any: ...

View File

@@ -1,6 +1,6 @@
import functools
from contextlib import ContextDecorator
from typing import Any, Optional, Callable
from typing import Any, Optional, Callable, Union
from django.core.handlers.wsgi import WSGIRequest
@@ -42,9 +42,12 @@ def npgettext(context: str, singular: str, plural: str, number: int) -> str: ...
gettext_lazy = gettext
ugettext_lazy = ugettext
pgettext_lazy = pgettext
ngettext_lazy = ngettext
ungettext_lazy = ungettext
npgettext_lazy = npgettext
def ngettext_lazy(singular: str, plural: str, number: Union[int, str, None]) -> str: ...
ungettext_lazy = ngettext_lazy
def npgettext_lazy(context: str, singular: str, plural: str, number: Union[int, str, None]) -> str: ...
def activate(language: str) -> None: ...
def deactivate() -> None: ...