Skip to content

Commit 4c63511

Browse files
authored
[Authlib] Annotate more (#15203)
1 parent 66a69d0 commit 4c63511

29 files changed

Lines changed: 213 additions & 149 deletions

stubs/Authlib/@tests/stubtest_allowlist.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ authlib.jose.rfc7518.AESAlgorithm.description
1010
authlib.jose.rfc7518.AESAlgorithm.name
1111
authlib.jose.rfc7518.ECDHESAlgorithm.description
1212
authlib.jose.rfc7518.ECDHESAlgorithm.name
13+
authlib.jose.rfc7518.CBCHS2EncAlgorithm.CEK_SIZE
14+
authlib.jose.rfc7518.CBCHS2EncAlgorithm.description
15+
authlib.jose.rfc7518.CBCHS2EncAlgorithm.name
1316
authlib.jose.rfc7518.jwe_algs.AESAlgorithm.description
1417
authlib.jose.rfc7518.jwe_algs.AESAlgorithm.name
1518
authlib.jose.rfc7518.jwe_algs.AESGCMAlgorithm.description
@@ -18,6 +21,20 @@ authlib.jose.rfc7518.jwe_algs.ECDHESAlgorithm.description
1821
authlib.jose.rfc7518.jwe_algs.ECDHESAlgorithm.name
1922
authlib.jose.rfc7518.jwe_algs.RSAAlgorithm.description
2023
authlib.jose.rfc7518.jwe_algs.RSAAlgorithm.name
24+
authlib.jose.rfc7518.jwe_encs.CBCHS2EncAlgorithm.CEK_SIZE
25+
authlib.jose.rfc7518.jwe_encs.CBCHS2EncAlgorithm.description
26+
authlib.jose.rfc7518.jwe_encs.CBCHS2EncAlgorithm.name
27+
authlib.jose.rfc7518.jwe_encs.GCMEncAlgorithm.CEK_SIZE
28+
authlib.jose.rfc7518.jwe_encs.GCMEncAlgorithm.description
29+
authlib.jose.rfc7518.jwe_encs.GCMEncAlgorithm.name
30+
authlib.jose.rfc7518.jws_algs.ECAlgorithm.description
31+
authlib.jose.rfc7518.jws_algs.ECAlgorithm.name
32+
authlib.jose.rfc7518.jws_algs.HMACAlgorithm.description
33+
authlib.jose.rfc7518.jws_algs.HMACAlgorithm.name
34+
authlib.jose.rfc7518.jws_algs.RSAAlgorithm.description
35+
authlib.jose.rfc7518.jws_algs.RSAAlgorithm.name
36+
authlib.jose.rfc7518.jws_algs.RSAPSSAlgorithm.description
37+
authlib.jose.rfc7518.jws_algs.RSAPSSAlgorithm.name
2138

2239
# Methods whose *args and **kwargs arguments are added dynamically due to the @hooked decorator:
2340
authlib.oauth2.rfc6749.AuthorizationCodeGrant.create_token_response

stubs/Authlib/authlib/common/urls.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ _ExplodedQueryString: TypeAlias = list[tuple[str, str]]
1111
def url_encode(params: _ExplodedQueryString) -> str: ...
1212
def url_decode(query: str) -> _ExplodedQueryString: ...
1313
def add_params_to_qs(query: str, params: _ExplodedQueryString) -> str: ...
14-
def add_params_to_uri(uri: str, params: _ExplodedQueryString, fragment: bool = False): ...
14+
def add_params_to_uri(uri: str, params: _ExplodedQueryString, fragment: bool = False) -> str: ...
1515
def quote(s: str, safe: bytes = b"/") -> str: ...
1616
def unquote(s: str | bytes) -> str: ...
1717
def quote_url(s: str) -> str: ...

stubs/Authlib/authlib/integrations/requests_client/oauth2_session.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class OAuth2Session(OAuth2Client):
2121
client_auth_class = OAuth2ClientAuth
2222
token_auth_class = OAuth2Auth
2323
oauth_error_class = OAuthError # type: ignore[assignment]
24-
SESSION_REQUEST_PARAMS: tuple[str, ...]
24+
SESSION_REQUEST_PARAMS: tuple[str, ...] # type: ignore[assignment]
2525
default_timeout: Incomplete
2626
def __init__(
2727
self,

stubs/Authlib/authlib/jose/drafts/_jwe_algorithms.pyi

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,18 @@ from collections.abc import Iterable
33
from typing import ClassVar, Final
44

55
from authlib.jose.rfc7516 import JWEAlgorithmWithTagAwareKeyAgreement
6+
from authlib.jose.rfc7518 import AESAlgorithm, ECKey
7+
from authlib.jose.rfc8037 import OKPKey
68

79
class ECDH1PUAlgorithm(JWEAlgorithmWithTagAwareKeyAgreement):
810
EXTRA_HEADERS: ClassVar[Iterable[str]]
9-
ALLOWED_KEY_CLS: Incomplete
11+
ALLOWED_KEY_CLS: tuple[type, ...]
1012
name: str
1113
description: str
1214
key_size: Incomplete
13-
aeskw: Incomplete
15+
aeskw: AESAlgorithm
1416
def __init__(self, key_size=None) -> None: ...
15-
def prepare_key(self, raw_data): ...
17+
def prepare_key(self, raw_data) -> ECKey | OKPKey: ...
1618
def generate_preset(self, enc_alg, key) -> dict[str, Incomplete]: ...
1719
def compute_shared_key(self, shared_key_e, shared_key_s): ...
1820
def compute_fixed_info(self, headers, bit_size, tag) -> bytes: ...
@@ -22,7 +24,7 @@ class ECDH1PUAlgorithm(JWEAlgorithmWithTagAwareKeyAgreement):
2224
self, recipient_key, sender_static_pubkey, sender_ephemeral_pubkey, headers, bit_size, tag
2325
) -> bytes: ...
2426
def generate_keys_and_prepare_headers(self, enc_alg, key, sender_key, preset=None) -> dict[str, Incomplete]: ...
25-
def agree_upon_key_and_wrap_cek(self, enc_alg, headers, key, sender_key, epk, cek, tag): ...
27+
def agree_upon_key_and_wrap_cek(self, enc_alg, headers, key, sender_key, epk, cek, tag) -> dict[str, Incomplete]: ...
2628
def wrap(self, enc_alg, headers, key, sender_key, preset=None) -> dict[str, Incomplete]: ...
2729
def unwrap(self, enc_alg, ek, headers, key, sender_key, tag=None) -> bytes: ...
2830

stubs/Authlib/authlib/jose/drafts/_jwe_enc_cryptodome.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ class XC20PEncAlgorithm(JWEEncAlgorithm):
99
key_size: Incomplete
1010
CEK_SIZE: Incomplete
1111
def __init__(self, key_size) -> None: ...
12-
def encrypt(self, msg, aad, iv, key): ...
13-
def decrypt(self, ciphertext, aad, iv, tag, key): ...
12+
def encrypt(self, msg, aad, iv, key) -> tuple[bytes, bytes]: ...
13+
def decrypt(self, ciphertext, aad, iv, tag, key) -> bytes: ...
Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
1-
from _typeshed import Incomplete
1+
from _typeshed import Incomplete, ReadableBuffer
2+
from collections.abc import Iterable
3+
from typing import SupportsBytes, SupportsIndex
24

3-
from .models import JWSObject
5+
from .models import JWSAlgorithm, JWSObject
46

57
class JsonWebSignature:
68
REGISTERED_HEADER_PARAMETER_NAMES: frozenset[str]
79
MAX_CONTENT_LENGTH: int
8-
ALGORITHMS_REGISTRY: dict[str, Incomplete]
10+
ALGORITHMS_REGISTRY: dict[str, JWSAlgorithm]
911
def __init__(self, algorithms=None, private_headers=None) -> None: ...
1012
@classmethod
11-
def register_algorithm(cls, algorithm) -> None: ...
13+
def register_algorithm(cls, algorithm: JWSAlgorithm) -> None: ...
1214
def serialize_compact(self, protected, payload, key) -> bytes: ...
13-
def deserialize_compact(self, s, key, decode=None) -> JWSObject: ...
14-
def serialize_json(self, header_obj, payload, key): ...
15+
def deserialize_compact(
16+
self, s: str | bytes | float | Iterable[SupportsIndex] | SupportsIndex | SupportsBytes | ReadableBuffer, key, decode=None
17+
) -> JWSObject: ...
18+
def serialize_json(self, header_obj, payload, key) -> dict[str, Incomplete]: ...
1519
def deserialize_json(self, obj, key, decode=None) -> JWSObject: ...
16-
def serialize(self, header, payload, key): ...
20+
def serialize(self, header, payload, key) -> dict[str, Incomplete] | bytes: ...
1721
def deserialize(self, s, key, decode=None) -> JWSObject: ...

stubs/Authlib/authlib/jose/rfc7515/models.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ from _typeshed import Incomplete
22
from typing_extensions import Self
33

44
class JWSAlgorithm:
5-
name: Incomplete
6-
description: Incomplete
5+
name: str | None
6+
description: str | None
77
algorithm_type: str
88
algorithm_location: str
99
def prepare_key(self, raw_data): ...
@@ -20,7 +20,7 @@ class JWSHeader(dict[str, object]):
2020
class JWSObject(dict[str, object]):
2121
header: Incomplete
2222
payload: Incomplete
23-
type: Incomplete
23+
type: str
2424
def __init__(self, header, payload, type: str = "compact") -> None: ...
2525
@property
2626
def headers(self): ...
Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,34 @@
1-
from _typeshed import Incomplete
1+
from _typeshed import Incomplete, ReadableBuffer
22
from collections import OrderedDict
3+
from collections.abc import Iterable
4+
from typing import SupportsBytes, SupportsIndex
5+
6+
from .models import JWEAlgorithmBase, JWEEncAlgorithm, JWEZipAlgorithm
37

48
class JsonWebEncryption:
59
REGISTERED_HEADER_PARAMETER_NAMES: frozenset[str]
6-
ALG_REGISTRY: dict[Incomplete, Incomplete]
7-
ENC_REGISTRY: dict[Incomplete, Incomplete]
8-
ZIP_REGISTRY: dict[Incomplete, Incomplete]
10+
ALG_REGISTRY: dict[str, JWEAlgorithmBase]
11+
ENC_REGISTRY: dict[str, JWEEncAlgorithm]
12+
ZIP_REGISTRY: dict[str, JWEZipAlgorithm]
913
def __init__(self, algorithms=None, private_headers=None) -> None: ...
1014
@classmethod
11-
def register_algorithm(cls, algorithm) -> None: ...
15+
def register_algorithm(cls, algorithm: JWEAlgorithmBase | JWEEncAlgorithm | JWEZipAlgorithm) -> None: ...
1216
def serialize_compact(self, protected, payload, key, sender_key=None) -> bytes: ...
1317
def serialize_json(self, header_obj, payload, keys, sender_key=None) -> OrderedDict[Incomplete, Incomplete]: ...
14-
def serialize(self, header, payload, key, sender_key=None): ...
15-
def deserialize_compact(self, s, key, decode=None, sender_key=None): ...
18+
def serialize(self, header, payload, key, sender_key=None) -> OrderedDict[Incomplete, Incomplete] | bytes: ...
19+
def deserialize_compact(
20+
self,
21+
s: str | bytes | float | Iterable[SupportsIndex] | SupportsIndex | SupportsBytes | ReadableBuffer,
22+
key,
23+
decode=None,
24+
sender_key=None,
25+
) -> dict[str, Incomplete]: ...
1626
def deserialize_json(self, obj, key, decode=None, sender_key=None) -> dict[str, Incomplete]: ...
17-
def deserialize(self, obj, key, decode=None, sender_key=None): ...
27+
def deserialize(self, obj, key, decode=None, sender_key=None) -> dict[str, Incomplete]: ...
1828
@staticmethod
1929
def parse_json(obj) -> dict[Incomplete, Incomplete]: ...
20-
def get_header_alg(self, header): ...
21-
def get_header_enc(self, header): ...
22-
def get_header_zip(self, header): ...
30+
def get_header_alg(self, header) -> JWEAlgorithmBase: ...
31+
def get_header_enc(self, header) -> JWEEncAlgorithm: ...
32+
def get_header_zip(self, header) -> JWEZipAlgorithm: ...
2333

2434
def prepare_key(alg, header, key): ...

stubs/Authlib/authlib/jose/rfc7516/models.pyi

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from _typeshed import Incomplete
22
from abc import ABCMeta
3-
from collections.abc import Iterable
3+
from collections.abc import Iterable, Sized
44
from typing import ClassVar
55
from typing_extensions import Self
66

@@ -28,13 +28,13 @@ class JWEEncAlgorithm:
2828
description: str | None
2929
algorithm_type: str
3030
algorithm_location: str
31-
IV_SIZE: Incomplete
32-
CEK_SIZE: Incomplete
33-
def generate_cek(self): ...
34-
def generate_iv(self): ...
35-
def check_iv(self, iv) -> None: ...
36-
def encrypt(self, msg, aad, iv, key): ...
37-
def decrypt(self, ciphertext, aad, iv, tag, key): ...
31+
IV_SIZE: int | None
32+
CEK_SIZE: int | None
33+
def generate_cek(self) -> bytes: ...
34+
def generate_iv(self) -> bytes: ...
35+
def check_iv(self, iv: Sized) -> None: ...
36+
def encrypt(self, msg, aad, iv, key) -> tuple[bytes, bytes]: ...
37+
def decrypt(self, ciphertext, aad, iv, tag, key) -> bytes: ...
3838

3939
class JWEZipAlgorithm:
4040
name: Incomplete

stubs/Authlib/authlib/jose/rfc7517/asymmetric_key.pyi

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
from _typeshed import Incomplete
2-
from typing import ClassVar
1+
from _typeshed import Incomplete, ReadableBuffer
2+
from collections.abc import Iterable
3+
from typing import ClassVar, Literal, SupportsBytes, SupportsIndex
34
from typing_extensions import Self
45

56
from authlib.jose.rfc7517 import Key
@@ -26,9 +27,22 @@ class AsymmetricKey(Key):
2627
def load_public_key(self): ...
2728
def as_dict(self, is_private: bool = False, **params) -> dict[Incomplete, Incomplete]: ...
2829
def as_key(self, is_private: bool = False): ...
29-
def as_bytes(self, encoding=None, is_private: bool = False, password=None): ...
30-
def as_pem(self, is_private: bool = False, password=None): ...
31-
def as_der(self, is_private: bool = False, password=None): ...
30+
def as_bytes(
31+
self,
32+
encoding: Literal["PEM", "DER"] | None = None,
33+
is_private: bool = False,
34+
password: str | bytes | float | Iterable[SupportsIndex] | SupportsIndex | SupportsBytes | ReadableBuffer | None = None,
35+
): ...
36+
def as_pem(
37+
self,
38+
is_private: bool = False,
39+
password: str | bytes | float | Iterable[SupportsIndex] | SupportsIndex | SupportsBytes | ReadableBuffer | None = None,
40+
): ...
41+
def as_der(
42+
self,
43+
is_private: bool = False,
44+
password: str | bytes | float | Iterable[SupportsIndex] | SupportsIndex | SupportsBytes | ReadableBuffer | None = None,
45+
): ...
3246
@classmethod
3347
def import_dict_key(cls, raw, options=None) -> Self: ...
3448
@classmethod

0 commit comments

Comments
 (0)