Skip to content

Commit

Permalink
Update type hints of core.signing (#1945)
Browse files Browse the repository at this point in the history
* Update type hints of `core.signing`

* Fix type hint of args

* [pre-commit.ci] auto fixes from pre-commit.com hooks

* Use Any

* Try using deprecated

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
Viicos and pre-commit-ci[bot] authored Feb 14, 2024
1 parent fefc54f commit 91c72c6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
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

0 comments on commit 91c72c6

Please sign in to comment.