Skip to content

Improve Authlib #13801

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

Merged
merged 2 commits into from
Apr 7, 2025
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
10 changes: 7 additions & 3 deletions stubs/Authlib/authlib/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
from .consts import homepage, version
from typing import Final

__version__ = version
__homepage__ = homepage
from .consts import author, homepage, version

__version__: Final = version
__homepage__: Final = homepage
__author__: Final = author
__license__: Final = "BSD-3-Clause"
36 changes: 26 additions & 10 deletions stubs/Authlib/authlib/common/encoding.pyi
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
def to_bytes(x, charset: str = "utf-8", errors: str = "strict") -> bytes | None: ...
def to_unicode(x, charset: str = "utf-8", errors: str = "strict") -> str | None: ...
def to_native(x, encoding: str = "ascii"): ...
def json_loads(s): ...
def json_dumps(data, ensure_ascii: bool = False): ...
def urlsafe_b64decode(s): ...
def urlsafe_b64encode(s): ...
def base64_to_int(s): ...
def int_to_base64(num): ...
def json_b64encode(text): ...
from _typeshed import ReadableBuffer
from collections.abc import Iterable
from typing import Any, SupportsBytes, SupportsIndex, overload

@overload
def to_bytes(x: None, charset: str = "utf-8", errors: str = "strict") -> None: ...
@overload
def to_bytes(
x: str | bytes | float | Iterable[SupportsIndex] | SupportsIndex | SupportsBytes | ReadableBuffer,
charset: str = "utf-8",
errors: str = "strict",
) -> bytes: ...
@overload
def to_unicode(x: None, charset: str = "utf-8", errors: str = "strict") -> None: ...
@overload
def to_unicode(x: object, charset: str = "utf-8", errors: str = "strict") -> str: ...
def to_native(x: str | bytes, encoding: str = "ascii") -> str: ...
def json_loads(s: str | bytes | bytearray) -> Any: ... # returns json.loads()
def json_dumps(data: Any, ensure_ascii: bool = False) -> str: ... # data pass to json.dumps()
def urlsafe_b64decode(s: bytes) -> bytes: ...
def urlsafe_b64encode(s: ReadableBuffer) -> bytes: ...
def base64_to_int(s: str | bytes | float | Iterable[SupportsIndex] | SupportsIndex | SupportsBytes | ReadableBuffer) -> int: ...
def int_to_base64(num: int) -> str: ...
def json_b64encode(
text: str | bytes | float | Iterable[SupportsIndex] | SupportsIndex | SupportsBytes | ReadableBuffer,
) -> bytes: ...
27 changes: 11 additions & 16 deletions stubs/Authlib/authlib/common/errors.pyi
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
from _typeshed import Incomplete
from typing import Literal

class AuthlibBaseError(Exception):
error: Incomplete
error: str | None
description: str
uri: Incomplete
def __init__(
self, error: Incomplete | None = None, description: Incomplete | None = None, uri: Incomplete | None = None
) -> None: ...
uri: str | None
def __init__(self, error: str | None = None, description: str | None = None, uri: str | None = None) -> None: ...

class AuthlibHTTPError(AuthlibBaseError):
status_code: int
def __init__(
self,
error: Incomplete | None = None,
description: Incomplete | None = None,
uri: Incomplete | None = None,
status_code: Incomplete | None = None,
self, error: str | None = None, description: str | None = None, uri: str | None = None, status_code: int | None = None
) -> None: ...
def get_error_description(self): ...
def get_body(self): ...
def get_headers(self): ...
uri: Incomplete
def __call__(self, uri: Incomplete | None = None): ...
def get_error_description(self) -> str: ...
def get_body(self) -> list[tuple[Literal["error", "error_description", "error_uri"], str | None]]: ...
def get_headers(self) -> list[tuple[str, str]]: ...
def __call__(
self, uri: str | None = None
) -> tuple[int, dict[Literal["error", "error_description", "error_uri"], str | None], list[tuple[str, str]]]: ...

class ContinueIteration(AuthlibBaseError): ...
4 changes: 3 additions & 1 deletion stubs/Authlib/authlib/common/security.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
UNICODE_ASCII_CHARACTER_SET: str
from typing import Final

UNICODE_ASCII_CHARACTER_SET: Final[str]

def generate_token(length: int = 30, chars: str = ...) -> str: ...
def is_secure_transport(uri: str) -> bool: ...
8 changes: 4 additions & 4 deletions stubs/Authlib/authlib/common/urls.pyi
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from collections.abc import Collection
from re import Pattern
from typing import Final
from typing_extensions import TypeAlias

always_safe: str
urlencoded: Collection[str]
INVALID_HEX_PATTERN: Pattern[str]
always_safe: Final[str]
urlencoded: Final[set[str]]
INVALID_HEX_PATTERN: Final[Pattern[str]]

_ExplodedQueryString: TypeAlias = list[tuple[str, str]]

Expand Down
14 changes: 7 additions & 7 deletions stubs/Authlib/authlib/consts.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from _typeshed import Incomplete
from typing import Final

name: str
version: str
author: str
homepage: str
default_user_agent: Incomplete
default_json_headers: Incomplete
name: Final[str]
version: Final[str]
author: Final[str]
homepage: Final[str]
default_user_agent: Final[str]
default_json_headers: Final[list[tuple[str, str]]]
6 changes: 1 addition & 5 deletions stubs/Authlib/authlib/deprecate.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
from _typeshed import Incomplete

class AuthlibDeprecationWarning(DeprecationWarning): ...

def deprecate(
message, version: Incomplete | None = None, link_uid: Incomplete | None = None, link_file: Incomplete | None = None
) -> None: ...
def deprecate(message: str, version: str | None = None, link_uid: str | None = None, link_file: str | None = None) -> None: ...
6 changes: 2 additions & 4 deletions stubs/Authlib/authlib/jose/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from _typeshed import Incomplete

from .errors import JoseError as JoseError
from .rfc7515 import (
JsonWebSignature as JsonWebSignature,
Expand All @@ -18,6 +16,8 @@ from .rfc7518 import ECKey as ECKey, OctKey as OctKey, RSAKey as RSAKey
from .rfc7519 import BaseClaims as BaseClaims, JsonWebToken as JsonWebToken, JWTClaims as JWTClaims
from .rfc8037 import OKPKey as OKPKey

jwt: JsonWebToken

__all__ = [
"JoseError",
"JsonWebSignature",
Expand All @@ -40,5 +40,3 @@ __all__ = [
"JWTClaims",
"jwt",
]

jwt: Incomplete
4 changes: 2 additions & 2 deletions stubs/Authlib/authlib/jose/rfc7519/claims.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from _typeshed import Incomplete

class BaseClaims(dict[str, object]):
REGISTERED_CLAIMS: Incomplete
REGISTERED_CLAIMS: list[str]
header: Incomplete
options: Incomplete
params: Incomplete
Expand All @@ -10,7 +10,7 @@ class BaseClaims(dict[str, object]):
def get_registered_claims(self): ...

class JWTClaims(BaseClaims):
REGISTERED_CLAIMS: Incomplete
REGISTERED_CLAIMS: list[str]
def validate(self, now: Incomplete | None = None, leeway: int = 0) -> None: ...
def validate_iss(self) -> None: ...
def validate_sub(self) -> None: ...
Expand Down
10 changes: 7 additions & 3 deletions stubs/Authlib/authlib/jose/util.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
def extract_header(header_segment, error_cls): ...
def extract_segment(segment, error_cls, name: str = "payload"): ...
def ensure_dict(s, structure_name): ...
from _typeshed import Incomplete

from authlib.common.errors import AuthlibBaseError

def extract_header(header_segment: bytes, error_cls: AuthlibBaseError) -> dict[Incomplete, Incomplete]: ...
def extract_segment(segment: bytes, error_cls: AuthlibBaseError, name: str = "payload") -> bytes: ...
def ensure_dict(s: object, structure_name: str) -> dict[Incomplete, Incomplete]: ...