Skip to content

Commit 22f478c

Browse files
committed
Remove redundant casts in RSAAlgorithm.prepare_key and ECAlgorithm.prepare_key
mypy 2.1.0 narrows `key` correctly via `isinstance(key, self._crypto_key_types)`, so the explicit `cast()` calls are redundant. Surfaced by CI on the previous commit.
1 parent 95791b1 commit 22f478c

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

jwt/algorithms.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ def check_key_length(self, key: AllowedRSAKeys) -> str | None:
443443

444444
def prepare_key(self, key: AllowedRSAKeys | str | bytes) -> AllowedRSAKeys:
445445
if isinstance(key, self._crypto_key_types):
446-
return cast(AllowedRSAKeys, key)
446+
return key
447447

448448
if not isinstance(key, (bytes, str)):
449449
raise TypeError("Expecting a PEM-formatted key.")
@@ -637,9 +637,8 @@ def _validate_curve(self, key: AllowedECKeys) -> None:
637637

638638
def prepare_key(self, key: AllowedECKeys | str | bytes) -> AllowedECKeys:
639639
if isinstance(key, self._crypto_key_types):
640-
ec_key = cast(AllowedECKeys, key)
641-
self._validate_curve(ec_key)
642-
return ec_key
640+
self._validate_curve(key)
641+
return key
643642

644643
if not isinstance(key, (bytes, str)):
645644
raise TypeError("Expecting a PEM-formatted key.")

0 commit comments

Comments
 (0)