Skip to content

Commit b8b3146

Browse files
toolnessgvanrossum
authored andcommitted
Add PyJWT type annotations (#1281)
1 parent b8a9604 commit b8b3146

6 files changed

Lines changed: 65 additions & 0 deletions

File tree

third_party/3/jwt/__init__.pyi

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
from typing import Mapping, Any, Optional, Union
2+
3+
from . import algorithms
4+
5+
def decode(jwt: Union[str, bytes], key: Union[str, bytes] = ...,
6+
verify: bool = ..., algorithms: Optional[Any] = ...,
7+
options: Optional[Mapping[Any, Any]] = ...,
8+
**kwargs: Any) -> Mapping[str, Any]: ...
9+
10+
def encode(payload: Mapping[str, Any], key: Union[str, bytes],
11+
algorithm: str = ..., headers: Optional[Mapping[str, Any]] = ...,
12+
json_encoder: Optional[Any] = ...) -> bytes: ...
13+
14+
def register_algorithm(alg_id: str,
15+
alg_obj: algorithms.Algorithm) -> None: ...
16+
17+
def unregister_algorithm(alg_id: str) -> None: ...
18+
19+
class InvalidTokenError(Exception): pass
20+
class DecodeError(InvalidTokenError): pass
21+
class ExpiredSignatureError(InvalidTokenError): pass
22+
class InvalidAudienceError(InvalidTokenError): pass
23+
class InvalidIssuerError(InvalidTokenError): pass
24+
class InvalidIssuedAtError(InvalidTokenError): pass
25+
class ImmatureSignatureError(InvalidTokenError): pass
26+
class InvalidKeyError(Exception): pass
27+
class InvalidAlgorithmError(InvalidTokenError): pass
28+
class MissingRequiredClaimError(InvalidTokenError): ...
29+
30+
# Compatibility aliases (deprecated)
31+
ExpiredSignature = ExpiredSignatureError
32+
InvalidAudience = InvalidAudienceError
33+
InvalidIssuer = InvalidIssuerError
34+
35+
# These aren't actually documented, but the package
36+
# exports them in __init__.py, so we should at least
37+
# make sure that mypy doesn't raise spurious errors
38+
# if they're used.
39+
get_unverified_header = ... # type: Any
40+
PyJWT = ... # type: Any
41+
PyJWS = ... # type: Any

third_party/3/jwt/algorithms.pyi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from typing import Any
2+
3+
class Algorithm(Any): ... # type: ignore

third_party/3/jwt/contrib/__init__.pyi

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from hashlib import _Hash as _HashAlg
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from typing import Any
2+
from jwt.algorithms import Algorithm
3+
4+
from . import _HashAlg
5+
6+
class ECAlgorithm(Algorithm):
7+
SHA256 = ... # type: _HashAlg
8+
SHA384 = ... # type: _HashAlg
9+
SHA512 = ... # type: _HashAlg
10+
def __init__(self, hash_alg: _HashAlg) -> None: ...
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from typing import Any
2+
from jwt.algorithms import Algorithm
3+
4+
from . import _HashAlg
5+
6+
class RSAAlgorithm(Algorithm):
7+
SHA256 = ... # type: _HashAlg
8+
SHA384 = ... # type: _HashAlg
9+
SHA512 = ... # type: _HashAlg
10+
def __init__(self, hash_alg: _HashAlg) -> None: ...

0 commit comments

Comments
 (0)