Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use PEP 570 syntax #1908

Merged
merged 1 commit into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion django-stubs/contrib/auth/password_validation.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ _UserModel: TypeAlias = Model

@type_check_only
class PasswordValidator(Protocol):
def validate(self, __password: str, __user: _UserModel | None = ...) -> None: ...
def validate(self, password: str, user: _UserModel | None = ..., /) -> None: ...
def get_help_text(self) -> str: ...

def get_default_password_validators() -> list[PasswordValidator]: ...
Expand Down
2 changes: 1 addition & 1 deletion django-stubs/contrib/gis/utils/layermapping.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class MissingForeignKey(LayerMapError): ...

@type_check_only
class _Writer(Protocol):
def write(self, __s: str) -> Any: ...
def write(self, s: str, /) -> Any: ...

class LayerMapping:
MULTI_TYPES: dict[int, OGRGeomType]
Expand Down
2 changes: 1 addition & 1 deletion django-stubs/core/checks/registry.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class CheckRegistry:
deployment_checks: set[_ProcessedCheckCallable]
def __init__(self) -> None: ...
@overload
def register(self, __check: _C) -> _ProcessedCheckCallable[_C]: ...
def register(self, check: _C, /) -> _ProcessedCheckCallable[_C]: ...
@overload
def register(self, *tags: str, **kwargs: Any) -> Callable[[_C], _ProcessedCheckCallable[_C]]: ...
def run_checks(
Expand Down
4 changes: 2 additions & 2 deletions django-stubs/core/paginator.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ _T = TypeVar("_T")
@type_check_only
class _SupportsPagination(Protocol[_T], Sized, Iterable):
@overload
def __getitem__(self, __index: int) -> _T: ...
def __getitem__(self, index: int, /) -> _T: ...
@overload
def __getitem__(self, __index: slice) -> _SupportsPagination[_T]: ...
def __getitem__(self, index: slice, /) -> _SupportsPagination[_T]: ...

class Paginator(Generic[_T]):
ELLIPSIS: ClassVar[_StrPromise]
Expand Down
4 changes: 2 additions & 2 deletions django-stubs/db/backends/ddl_references.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ from typing import Any, Protocol, type_check_only
class _QuoteCallable(Protocol):
"""Get rid of `cannot assign to method`"""

def __call__(self, __column: str) -> str: ...
def __call__(self, column: str, /) -> str: ...

class Reference:
def references_table(self, table: Any) -> bool: ...
Expand Down Expand Up @@ -40,7 +40,7 @@ class Columns(TableColumns):
class _NameCallable(Protocol):
"""Get rid of `cannot assign to method`"""

def __call__(self, __table: str, __columns: list[str], __suffix: str) -> str: ...
def __call__(self, table: str, columns: list[str], suffix: str, /) -> str: ...

class IndexName(TableColumns):
columns: list[str]
Expand Down
2 changes: 1 addition & 1 deletion django-stubs/db/migrations/executor.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ from .state import ProjectState

@type_check_only
class _ProgressCallbackT(Protocol):
def __call__(self, __action: str, __migration: Migration | None = ..., __fake: bool | None = ...) -> None: ...
def __call__(self, action: str, migration: Migration | None = ..., fake: bool | None = ..., /) -> None: ...

class MigrationExecutor:
connection: BaseDatabaseWrapper
Expand Down
2 changes: 1 addition & 1 deletion django-stubs/db/migrations/operations/special.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class RunSQL(Operation):

@type_check_only
class _CodeCallable(Protocol):
def __call__(self, __state_apps: StateApps, __schema_editor: BaseDatabaseSchemaEditor) -> None: ...
def __call__(self, state_apps: StateApps, schema_editor: BaseDatabaseSchemaEditor, /) -> None: ...

class RunPython(Operation):
code: _CodeCallable
Expand Down
2 changes: 1 addition & 1 deletion django-stubs/db/models/fields/files.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ _M = TypeVar("_M", bound=Model, contravariant=True)

@type_check_only
class _UploadToCallable(Protocol[_M]):
def __call__(self, __instance: _M, __filename: str) -> _PathCompatible: ...
def __call__(self, instance: _M, filename: str, /) -> _PathCompatible: ...

class FileField(Field):
storage: Storage
Expand Down
2 changes: 1 addition & 1 deletion django-stubs/forms/fields.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ class ChoiceField(Field):

@type_check_only
class _CoerceCallable(Protocol):
def __call__(self, __value: Any) -> Any: ...
def __call__(self, value: Any, /) -> Any: ...

class TypedChoiceField(ChoiceField):
coerce: _CoerceCallable
Expand Down
2 changes: 1 addition & 1 deletion django-stubs/forms/widgets.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class TimeInput(DateTimeBaseInput):
def boolean_check(v: Any) -> bool: ...
@type_check_only
class _CheckCallable(Protocol):
def __call__(self, __value: Any) -> bool: ...
def __call__(self, value: Any, /) -> bool: ...

class CheckboxInput(Input):
check_test: _CheckCallable
Expand Down
8 changes: 4 additions & 4 deletions django-stubs/http/request.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ class QueryDict(MultiValueDict[str, str]):
def appendlist(self, key: str | bytes, value: str | bytes) -> None: ...
# Fake signature (because *args is used in source, but it fails with more that 1 argument)
@overload
def pop(self, __key: str | bytes) -> str: ...
def pop(self, key: str | bytes, /) -> str: ...
@overload
def pop(self, __key: str | bytes, __default: str | _Z = ...) -> str | _Z: ...
def pop(self, key: str | bytes, default: str | _Z = ..., /) -> str | _Z: ...
def popitem(self) -> tuple[str, str]: ...
def clear(self) -> None: ...
def setdefault(self, key: str | bytes, default: str | bytes | None = ...) -> str: ...
Expand All @@ -181,9 +181,9 @@ class _ImmutableQueryDict(QueryDict):
def appendlist(self, key: str | bytes, value: str | bytes) -> NoReturn: ...
# Fake signature (because *args is used in source, but it fails with more that 1 argument)
@overload
def pop(self, __key: str | bytes) -> NoReturn: ...
def pop(self, key: str | bytes, /) -> NoReturn: ...
@overload
def pop(self, __key: str | bytes, __default: str | _Z = ...) -> NoReturn: ...
def pop(self, key: str | bytes, default: str | _Z = ..., /) -> NoReturn: ...
def popitem(self) -> NoReturn: ...
def clear(self) -> NoReturn: ...
def setdefault(self, key: str | bytes, default: str | bytes | None = ...) -> NoReturn: ...
Expand Down
2 changes: 1 addition & 1 deletion django-stubs/utils/datastructures.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class ImmutableList(tuple[_V, ...]):
class _ItemCallable(Protocol[_V]):
"""Don't mess with arguments when assigning in class body in stub"""

def __call__(self, __value: _V) -> _V: ...
def __call__(self, value: _V, /) -> _V: ...

class DictWrapper(dict[str, _V]):
func: _ItemCallable[_V]
Expand Down
4 changes: 2 additions & 2 deletions django-stubs/utils/deprecation.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ class DeprecationInstanceCheck(type):

@type_check_only
class _GetResponseCallable(Protocol):
def __call__(self, __request: HttpRequest) -> HttpResponseBase: ...
def __call__(self, request: HttpRequest, /) -> HttpResponseBase: ...

@type_check_only
class _AsyncGetResponseCallable(Protocol):
def __call__(self, __request: HttpRequest) -> Awaitable[HttpResponseBase]: ...
def __call__(self, request: HttpRequest, /) -> Awaitable[HttpResponseBase]: ...

class MiddlewareMixin:
sync_capable: bool
Expand Down
26 changes: 13 additions & 13 deletions django-stubs/utils/functional.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@ class Promise:

@type_check_only
class _StrPromise(Promise):
def __add__(self, __s: str) -> str: ...
def __contains__(self, __o: str) -> bool: ...
def __ge__(self, __x: str) -> bool: ...
def __getitem__(self, __i: SupportsIndex | slice) -> str: ...
def __gt__(self, __x: str) -> bool: ...
def __le__(self, __x: str) -> bool: ...
def __add__(self, s: str, /) -> str: ...
def __contains__(self, o: str, /) -> bool: ...
def __ge__(self, x: str, /) -> bool: ...
def __getitem__(self, i: SupportsIndex | slice, /) -> str: ...
def __gt__(self, x: str, /) -> bool: ...
def __le__(self, x: str, /) -> bool: ...
# __len__ needed here because it defined abstract in Sequence[str]
def __len__(self) -> int: ...
def __lt__(self, __x: str) -> bool: ...
def __mod__(self, __x: Any) -> str: ...
def __mul__(self, __n: SupportsIndex) -> str: ...
def __rmul__(self, __n: SupportsIndex) -> str: ...
def __lt__(self, x: str, /) -> bool: ...
def __mod__(self, x: Any, /) -> str: ...
def __mul__(self, n: SupportsIndex, /) -> str: ...
def __rmul__(self, n: SupportsIndex, /) -> str: ...
# Mypy requires this for the attribute hook to take effect
def __getattribute__(self, __name: str) -> Any: ...
def __getattribute__(self, name: str, /) -> Any: ...

_StrOrPromise: TypeAlias = str | _StrPromise # noqa: PYI047
_C = TypeVar("_C", bound=Callable)
Expand Down Expand Up @@ -104,6 +104,6 @@ class _Getter(Protocol[_Get]): # noqa: PYI046
"""

@overload
def __get__(self, __instance: None, __typeobj: type[Any] | None) -> Self: ...
def __get__(self, instance: None, typeobj: type[Any] | None, /) -> Self: ...
@overload
def __get__(self, __instance: Any, __typeobj: type[Any] | None) -> _Get: ...
def __get__(self, instance: Any, typeobj: type[Any] | None, /) -> _Get: ...
2 changes: 1 addition & 1 deletion django-stubs/utils/translation/trans_real.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ language_code_prefix_re: Pattern[str]

@type_check_only
class _PluralCallable(Protocol):
def __call__(self, __n: int) -> int: ...
def __call__(self, n: int, /) -> int: ...

def reset_cache(*, setting: str, **kwargs: Any) -> None: ...

Expand Down
2 changes: 1 addition & 1 deletion tests/typecheck/contrib/auth/test_misc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from django.contrib.sessions.middleware import SessionMiddleware
from django.http import HttpRequest, HttpResponse

def get_response(__request: HttpRequest) -> HttpResponse:
def get_response(request: HttpRequest, /) -> HttpResponse:
return HttpResponse()

request = HttpRequest()
Expand Down