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

Update type hints of core.signing #1945

Merged
merged 5 commits into from
Feb 14, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 30 additions & 8 deletions django-stubs/core/signing.pyi
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
from datetime import timedelta
from typing import Any, Protocol, type_check_only
from typing import Any, Protocol, overload, type_check_only

from typing_extensions import deprecated

BASE62_ALPHABET: str

class BadSignature(Exception): ...
class SignatureExpired(BadSignature): ...

def b62_encode(s: int) -> str: ...
def b62_decode(s: str) -> int: ...
def b64_encode(s: bytes) -> bytes: ...
def b64_decode(s: bytes) -> bytes: ...
def base64_hmac(salt: str, value: bytes | str, key: bytes | str, algorithm: str = ...) -> str: ...
def base64_hmac(salt: bytes | str, value: bytes | str, key: bytes | str, algorithm: str = ...) -> str: ...
def get_cookie_signer(salt: str = ...) -> TimestampSigner: ...
@type_check_only
class Serializer(Protocol):
Expand All @@ -20,31 +26,47 @@ class JSONSerializer:
def dumps(
obj: Any,
key: bytes | str | None = ...,
salt: str = ...,
salt: bytes | str = ...,
serializer: type[Serializer] = ...,
compress: bool = ...,
) -> str: ...
def loads(
s: str,
key: bytes | str | None = ...,
salt: str = ...,
salt: bytes | str = ...,
serializer: type[Serializer] = ...,
max_age: int | timedelta | None = ...,
fallback_keys: list[str | bytes] | None = ...,
) -> Any: ...

class Signer:
key: str
key: bytes | str
fallback_keys: list[bytes | str]
sep: str
salt: str
salt: bytes | str
algorithm: str
@overload
def __init__(
self,
*,
key: bytes | str | None = ...,
sep: str = ...,
salt: bytes | str | None = ...,
algorithm: str | None = ...,
fallback_keys: list[bytes | str] | None = ...,
) -> None: ...
@overload
@deprecated("Passing positional arguments to Signer is deprecated and will be removed in Django 5.1")
def __init__(
self,
*args: Any,
key: bytes | str | None = ...,
sep: str = ...,
salt: str | None = ...,
salt: bytes | str | None = ...,
algorithm: str | None = ...,
fallback_keys: list[bytes | str] | None = ...,
) -> None: ...
def signature(self, value: bytes | str) -> str: ...
def signature(self, value: bytes | str, key: bytes | str | None = ...) -> str: ...
def sign(self, value: str) -> str: ...
def unsign(self, signed_value: str) -> str: ...
def sign_object(
Expand Down
6 changes: 0 additions & 6 deletions scripts/stubtest/allowlist_todo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -754,12 +754,6 @@ django.core.management.utils.run_formatters
django.core.management.utils.sentinel
django.core.servers.basehttp.ServerHandler.__init__
django.core.servers.basehttp.ThreadedWSGIServer.__init__
django.core.signing.BASE62_ALPHABET
django.core.signing.Signer.__init__
django.core.signing.Signer.signature
django.core.signing.b62_decode
django.core.signing.b62_encode
django.core.signing.loads
django.db.backends.ddl_references.Expressions
django.db.backends.mysql.base
django.db.backends.mysql.features.DatabaseFeatures.can_rename_index
Expand Down