Skip to content

Commit

Permalink
Change InlineModelAdmin.formset to Type[BaseInlineFormSet] (typeddjan…
Browse files Browse the repository at this point in the history
…go#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
  • Loading branch information
Eboreg authored Nov 6, 2020
1 parent e837dac commit a0d61c0
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
4 changes: 2 additions & 2 deletions django-stubs/contrib/admin/options.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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] = ...
Expand Down
6 changes: 6 additions & 0 deletions django-stubs/contrib/auth/tokens.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from datetime import date
from typing import Any, Optional

from django.contrib.auth.base_user import AbstractBaseUser
Expand All @@ -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
15 changes: 12 additions & 3 deletions django-stubs/contrib/humanize/templatetags/humanize.pyi
Original file line number Diff line number Diff line change
@@ -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: ...
11 changes: 7 additions & 4 deletions django-stubs/utils/translation/__init__.pyi
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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: ...
Expand Down

0 comments on commit a0d61c0

Please sign in to comment.