Skip to content

Commit e26a15f

Browse files
authored
Improve Authlib (#13801)
1 parent 5e3e056 commit e26a15f

File tree

10 files changed

+70
-55
lines changed

10 files changed

+70
-55
lines changed

stubs/Authlib/authlib/__init__.pyi

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
from .consts import homepage, version
1+
from typing import Final
22

3-
__version__ = version
4-
__homepage__ = homepage
3+
from .consts import author, homepage, version
4+
5+
__version__: Final = version
6+
__homepage__: Final = homepage
7+
__author__: Final = author
8+
__license__: Final = "BSD-3-Clause"
+26-10
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,26 @@
1-
def to_bytes(x, charset: str = "utf-8", errors: str = "strict") -> bytes | None: ...
2-
def to_unicode(x, charset: str = "utf-8", errors: str = "strict") -> str | None: ...
3-
def to_native(x, encoding: str = "ascii"): ...
4-
def json_loads(s): ...
5-
def json_dumps(data, ensure_ascii: bool = False): ...
6-
def urlsafe_b64decode(s): ...
7-
def urlsafe_b64encode(s): ...
8-
def base64_to_int(s): ...
9-
def int_to_base64(num): ...
10-
def json_b64encode(text): ...
1+
from _typeshed import ReadableBuffer
2+
from collections.abc import Iterable
3+
from typing import Any, SupportsBytes, SupportsIndex, overload
4+
5+
@overload
6+
def to_bytes(x: None, charset: str = "utf-8", errors: str = "strict") -> None: ...
7+
@overload
8+
def to_bytes(
9+
x: str | bytes | float | Iterable[SupportsIndex] | SupportsIndex | SupportsBytes | ReadableBuffer,
10+
charset: str = "utf-8",
11+
errors: str = "strict",
12+
) -> bytes: ...
13+
@overload
14+
def to_unicode(x: None, charset: str = "utf-8", errors: str = "strict") -> None: ...
15+
@overload
16+
def to_unicode(x: object, charset: str = "utf-8", errors: str = "strict") -> str: ...
17+
def to_native(x: str | bytes, encoding: str = "ascii") -> str: ...
18+
def json_loads(s: str | bytes | bytearray) -> Any: ... # returns json.loads()
19+
def json_dumps(data: Any, ensure_ascii: bool = False) -> str: ... # data pass to json.dumps()
20+
def urlsafe_b64decode(s: bytes) -> bytes: ...
21+
def urlsafe_b64encode(s: ReadableBuffer) -> bytes: ...
22+
def base64_to_int(s: str | bytes | float | Iterable[SupportsIndex] | SupportsIndex | SupportsBytes | ReadableBuffer) -> int: ...
23+
def int_to_base64(num: int) -> str: ...
24+
def json_b64encode(
25+
text: str | bytes | float | Iterable[SupportsIndex] | SupportsIndex | SupportsBytes | ReadableBuffer,
26+
) -> bytes: ...
+11-16
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,21 @@
1-
from _typeshed import Incomplete
1+
from typing import Literal
22

33
class AuthlibBaseError(Exception):
4-
error: Incomplete
4+
error: str | None
55
description: str
6-
uri: Incomplete
7-
def __init__(
8-
self, error: Incomplete | None = None, description: Incomplete | None = None, uri: Incomplete | None = None
9-
) -> None: ...
6+
uri: str | None
7+
def __init__(self, error: str | None = None, description: str | None = None, uri: str | None = None) -> None: ...
108

119
class AuthlibHTTPError(AuthlibBaseError):
1210
status_code: int
1311
def __init__(
14-
self,
15-
error: Incomplete | None = None,
16-
description: Incomplete | None = None,
17-
uri: Incomplete | None = None,
18-
status_code: Incomplete | None = None,
12+
self, error: str | None = None, description: str | None = None, uri: str | None = None, status_code: int | None = None
1913
) -> None: ...
20-
def get_error_description(self): ...
21-
def get_body(self): ...
22-
def get_headers(self): ...
23-
uri: Incomplete
24-
def __call__(self, uri: Incomplete | None = None): ...
14+
def get_error_description(self) -> str: ...
15+
def get_body(self) -> list[tuple[Literal["error", "error_description", "error_uri"], str | None]]: ...
16+
def get_headers(self) -> list[tuple[str, str]]: ...
17+
def __call__(
18+
self, uri: str | None = None
19+
) -> tuple[int, dict[Literal["error", "error_description", "error_uri"], str | None], list[tuple[str, str]]]: ...
2520

2621
class ContinueIteration(AuthlibBaseError): ...
+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
UNICODE_ASCII_CHARACTER_SET: str
1+
from typing import Final
2+
3+
UNICODE_ASCII_CHARACTER_SET: Final[str]
24

35
def generate_token(length: int = 30, chars: str = ...) -> str: ...
46
def is_secure_transport(uri: str) -> bool: ...

stubs/Authlib/authlib/common/urls.pyi

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
from collections.abc import Collection
21
from re import Pattern
2+
from typing import Final
33
from typing_extensions import TypeAlias
44

5-
always_safe: str
6-
urlencoded: Collection[str]
7-
INVALID_HEX_PATTERN: Pattern[str]
5+
always_safe: Final[str]
6+
urlencoded: Final[set[str]]
7+
INVALID_HEX_PATTERN: Final[Pattern[str]]
88

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

stubs/Authlib/authlib/consts.pyi

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
from _typeshed import Incomplete
1+
from typing import Final
22

3-
name: str
4-
version: str
5-
author: str
6-
homepage: str
7-
default_user_agent: Incomplete
8-
default_json_headers: Incomplete
3+
name: Final[str]
4+
version: Final[str]
5+
author: Final[str]
6+
homepage: Final[str]
7+
default_user_agent: Final[str]
8+
default_json_headers: Final[list[tuple[str, str]]]

stubs/Authlib/authlib/deprecate.pyi

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
from _typeshed import Incomplete
2-
31
class AuthlibDeprecationWarning(DeprecationWarning): ...
42

5-
def deprecate(
6-
message, version: Incomplete | None = None, link_uid: Incomplete | None = None, link_file: Incomplete | None = None
7-
) -> None: ...
3+
def deprecate(message: str, version: str | None = None, link_uid: str | None = None, link_file: str | None = None) -> None: ...

stubs/Authlib/authlib/jose/__init__.pyi

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from _typeshed import Incomplete
2-
31
from .errors import JoseError as JoseError
42
from .rfc7515 import (
53
JsonWebSignature as JsonWebSignature,
@@ -18,6 +16,8 @@ from .rfc7518 import ECKey as ECKey, OctKey as OctKey, RSAKey as RSAKey
1816
from .rfc7519 import BaseClaims as BaseClaims, JsonWebToken as JsonWebToken, JWTClaims as JWTClaims
1917
from .rfc8037 import OKPKey as OKPKey
2018

19+
jwt: JsonWebToken
20+
2121
__all__ = [
2222
"JoseError",
2323
"JsonWebSignature",
@@ -40,5 +40,3 @@ __all__ = [
4040
"JWTClaims",
4141
"jwt",
4242
]
43-
44-
jwt: Incomplete

stubs/Authlib/authlib/jose/rfc7519/claims.pyi

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from _typeshed import Incomplete
22

33
class BaseClaims(dict[str, object]):
4-
REGISTERED_CLAIMS: Incomplete
4+
REGISTERED_CLAIMS: list[str]
55
header: Incomplete
66
options: Incomplete
77
params: Incomplete
@@ -10,7 +10,7 @@ class BaseClaims(dict[str, object]):
1010
def get_registered_claims(self): ...
1111

1212
class JWTClaims(BaseClaims):
13-
REGISTERED_CLAIMS: Incomplete
13+
REGISTERED_CLAIMS: list[str]
1414
def validate(self, now: Incomplete | None = None, leeway: int = 0) -> None: ...
1515
def validate_iss(self) -> None: ...
1616
def validate_sub(self) -> None: ...

stubs/Authlib/authlib/jose/util.pyi

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1-
def extract_header(header_segment, error_cls): ...
2-
def extract_segment(segment, error_cls, name: str = "payload"): ...
3-
def ensure_dict(s, structure_name): ...
1+
from _typeshed import Incomplete
2+
3+
from authlib.common.errors import AuthlibBaseError
4+
5+
def extract_header(header_segment: bytes, error_cls: AuthlibBaseError) -> dict[Incomplete, Incomplete]: ...
6+
def extract_segment(segment: bytes, error_cls: AuthlibBaseError, name: str = "payload") -> bytes: ...
7+
def ensure_dict(s: object, structure_name: str) -> dict[Incomplete, Incomplete]: ...

0 commit comments

Comments
 (0)