Skip to content

Commit 8aba046

Browse files
authored
Merge pull request #190 from jschlyter/type_cleanup
Type cleanup
2 parents e252046 + da6d7a2 commit 8aba046

37 files changed

+80
-111
lines changed

CONTRIBUTING.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ All contributions to the Python JwtConnect packages are welcome!
44

55
Note that as this library is planned to be used in high-profile production code,
66
we insist on a very high standards for the code and design, but don't feel shy:
7-
discuss your plans over
7+
discuss your plans over
88
[GitHub Issues](https://github.com/openid/JWTConnect-Python-OidcMsg/issues) and the
99
[mailing list](http://lists.openid.net/mailman/listinfo/openid-specs-ab), and
1010
send in those pull requests!
@@ -42,14 +42,14 @@ requests).
4242
Before you work on a big new feature, get in touch to make sure that your work
4343
is inline with the direction of the project and get input on your architecture.
4444
You can file an [Issue](https://github.com/openid/JWTConnect-Python-OidcMsg/issues)
45-
discussing your proposal, or email the
46-
[list](http://lists.openid.net/mailman/listinfo/openid-specs-ab).
45+
discussing your proposal, or email the
46+
[list](http://lists.openid.net/mailman/listinfo/openid-specs-ab).
4747

4848
## Coding Standards
4949

5050
The JWTCOnnect-Python-OidcMsg library follows the
51-
[PEP8](https://www.python.org/dev/peps/pep-0008/)
52-
coding style for Python implementations. Please review your own code
51+
[PEP8](https://www.python.org/dev/peps/pep-0008/)
52+
coding style for Python implementations. Please review your own code
5353
for adherence to the standard.
5454

5555
## Pull Request Reviews

doc/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ help:
1717
# Catch-all target: route all unknown targets to Sphinx using the new
1818
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
1919
%: Makefile
20-
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
20+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ dev = [
4343
"sphinx>=3.5.2",
4444
"sphinx-autobuild>=2021.3.14",
4545
"coverage>=7",
46-
"ruff>=0.9.9",
46+
"ruff>=0.14.4",
4747
"pytest-ruff>=0.3.2"
4848
]
4949

src/cryptojwt/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""JSON Web Token"""
22

33
import logging
4-
from importlib.metadata import version, PackageNotFoundError
4+
from importlib.metadata import PackageNotFoundError, version
55

66
from cryptojwt.jwe.jwe import JWE
77
from cryptojwt.jwk import JWK

src/cryptojwt/jwe/fernet.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import base64
22
import os
3-
from typing import Optional, Union
43

54
from cryptography.fernet import Fernet
65
from cryptography.hazmat.primitives import hashes
@@ -15,12 +14,12 @@
1514
class FernetEncrypter(Encrypter):
1615
def __init__(
1716
self,
18-
password: Optional[str] = None,
19-
salt: Optional[bytes] = "",
20-
key: Optional[bytes] = None,
21-
hash_alg: Optional[str] = "SHA256",
22-
digest_size: Optional[int] = 0,
23-
iterations: Optional[int] = DEFAULT_ITERATIONS,
17+
password: str | None = None,
18+
salt: bytes | None = "",
19+
key: bytes | None = None,
20+
hash_alg: str | None = "SHA256",
21+
digest_size: int | None = 0,
22+
iterations: int | None = DEFAULT_ITERATIONS,
2423
):
2524
Encrypter.__init__(self)
2625

@@ -45,14 +44,14 @@ def __init__(
4544

4645
self.core = Fernet(self.key)
4746

48-
def encrypt(self, msg: Union[str, bytes], **kwargs) -> bytes:
47+
def encrypt(self, msg: str | bytes, **kwargs) -> bytes:
4948
text = as_bytes(msg)
5049
# Padding to block size of AES
5150
if len(text) % 16:
5251
text += b" " * (16 - len(text) % 16)
5352
return self.core.encrypt(as_bytes(text))
5453

55-
def decrypt(self, msg: Union[str, bytes], **kwargs) -> bytes:
54+
def decrypt(self, msg: str | bytes, **kwargs) -> bytes:
5655
dec_text = self.core.decrypt(as_bytes(msg))
5756
dec_text = dec_text.rstrip(b" ")
5857
return dec_text

src/cryptojwt/jwk/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import hashlib
33
import json
44
import ssl
5-
from typing import List
65

76
from ..exception import UnsupportedAlgorithm
87
from ..utils import as_bytes, as_unicode, b64e, base64url_to_long
@@ -21,7 +20,7 @@ class JWK:
2120
"""
2221

2322
members = ["kty", "alg", "use", "kid", "x5c", "x5t", "x5u", "key_ops"]
24-
longs: List[str] = []
23+
longs: list[str] = []
2524
public_members = ["kty", "alg", "use", "kid", "x5c", "x5t", "x5u", "key_ops"]
2625
required = ["kty"]
2726

@@ -130,7 +129,7 @@ def __init__(
130129
self.kid = as_unicode(kid)
131130

132131
if key_ops:
133-
self.key_ops: List[str] = []
132+
self.key_ops: list[str] = []
134133
for ops in key_ops:
135134
if isinstance(ops, str):
136135
self.key_ops.append(ops)

src/cryptojwt/jwk/okp.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from typing import Union
2-
31
from cryptography.hazmat.primitives import serialization
42
from cryptography.hazmat.primitives.asymmetric import ed448, ed25519, x448, x25519
53

@@ -14,18 +12,16 @@
1412
import_public_key_from_pem_file,
1513
)
1614

17-
OKPPublicKey = Union[
18-
ed25519.Ed25519PublicKey,
19-
ed448.Ed448PublicKey,
20-
x25519.X25519PublicKey,
21-
x448.X448PublicKey,
22-
]
23-
OKPPrivateKey = Union[
24-
ed25519.Ed25519PrivateKey,
25-
ed448.Ed448PrivateKey,
26-
x25519.X25519PrivateKey,
27-
x448.X448PrivateKey,
28-
]
15+
OKPPublicKey = (
16+
ed25519.Ed25519PublicKey | ed448.Ed448PublicKey | x25519.X25519PublicKey | x448.X448PublicKey
17+
)
18+
19+
OKPPrivateKey = (
20+
ed25519.Ed25519PrivateKey
21+
| ed448.Ed448PrivateKey
22+
| x25519.X25519PrivateKey
23+
| x448.X448PrivateKey
24+
)
2925

3026
OKP_CRV2PUBLIC = {
3127
"Ed25519": ed25519.Ed25519PublicKey,

src/cryptojwt/jwt.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
import logging
66
import time
77
import uuid
8+
from collections.abc import MutableMapping
89
from json import JSONDecodeError
9-
from typing import Dict, List, MutableMapping, Optional
1010

1111
from .exception import HeaderError, VerificationError
1212
from .jwe.jwe import JWE, factory as jwe_factory
@@ -83,15 +83,15 @@ def __init__(
8383
encrypt: bool = False,
8484
enc_enc: str = "A128GCM",
8585
enc_alg: str = "RSA-OAEP-256",
86-
msg_cls: Optional[MutableMapping] = None,
87-
iss2msg_cls: Optional[Dict[str, str]] = None,
88-
skew: Optional[int] = 15,
89-
allowed_sign_algs: Optional[List[str]] = None,
90-
allowed_enc_algs: Optional[List[str]] = None,
91-
allowed_enc_encs: Optional[List[str]] = None,
92-
allowed_max_lifetime: Optional[int] = None,
93-
zip: Optional[str] = "",
94-
typ2msg_cls: Optional[Dict] = None,
86+
msg_cls: type[MutableMapping] | None = None,
87+
iss2msg_cls: dict[str, str] | None = None,
88+
skew: int | None = 15,
89+
allowed_sign_algs: list[str] | None = None,
90+
allowed_enc_algs: list[str] | None = None,
91+
allowed_enc_encs: list[str] | None = None,
92+
allowed_max_lifetime: int | None = None,
93+
zip: str | None = "",
94+
typ2msg_cls: dict | None = None,
9595
):
9696
self.key_jar = key_jar # KeyJar instance
9797
self.iss = iss # My identifier
@@ -208,13 +208,13 @@ def message(self, signing_key, **kwargs):
208208

209209
def pack(
210210
self,
211-
payload: Optional[dict] = None,
212-
kid: Optional[str] = "",
213-
issuer_id: Optional[str] = "",
214-
recv: Optional[str] = "",
215-
aud: Optional[str] = None,
216-
iat: Optional[int] = None,
217-
jws_headers: Optional[Dict[str, str]] = None,
211+
payload: dict | None = None,
212+
kid: str | None = "",
213+
issuer_id: str | None = "",
214+
recv: str | None = "",
215+
aud: str | None = None,
216+
iat: int | None = None,
217+
jws_headers: dict[str, str] | None = None,
218218
**kwargs,
219219
) -> str:
220220
"""

src/cryptojwt/key_bundle.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import time
1010
from datetime import datetime
1111
from functools import cmp_to_key
12-
from typing import List, Optional
1312

1413
import requests
1514

@@ -808,7 +807,7 @@ def difference(self, bundle):
808807

809808
return [k for k in self.keys() if k not in bundle]
810809

811-
def dump(self, exclude_attributes: Optional[List[str]] = None):
810+
def dump(self, exclude_attributes: list[str] | None = None):
812811
if exclude_attributes is None:
813812
exclude_attributes = []
814813

src/cryptojwt/key_issuer.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import json
22
import logging
33
import os
4-
from typing import List, Optional
54

65
from requests import request
76

@@ -345,7 +344,7 @@ def __len__(self):
345344
nr += len(kb)
346345
return nr
347346

348-
def dump(self, exclude_attributes: Optional[List[str]] = None) -> dict:
347+
def dump(self, exclude_attributes: list[str] | None = None) -> dict:
349348
"""
350349
Returns the content as a dictionary.
351350

0 commit comments

Comments
 (0)