Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use sequence for typing rather than list #970

Merged
merged 4 commits into from
Aug 7, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
chore: use sequence for typing rather than list
there's no reason we need to use `List` for the typing of issuers & other parameters - the `Sequence` type allows us to accept more types such as `tuple` and `set` which still support the behavior we need
  • Loading branch information
imnotjames authored Aug 5, 2024
commit cc9eaef7ae540ec22d155e1cfd5e9f3aa99e38bd
16 changes: 8 additions & 8 deletions jwt/api_jwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import json
import warnings
from calendar import timegm
from collections.abc import Iterable
from collections.abc import Iterable, Sequence
from datetime import datetime, timedelta, timezone
from typing import TYPE_CHECKING, Any, List
from typing import TYPE_CHECKING, Any

from . import api_jws
from .exceptions import (
Expand All @@ -31,7 +31,7 @@ def __init__(self, options: dict[str, Any] | None = None) -> None:
self.options: dict[str, Any] = {**self._get_default_options(), **options}

@staticmethod
def _get_default_options() -> dict[str, bool | list[str]]:
def _get_default_options() -> dict[str, bool | Sequence[str]]:
return {
"verify_signature": True,
"verify_exp": True,
Expand Down Expand Up @@ -102,7 +102,7 @@ def decode_complete(
self,
jwt: str | bytes,
key: AllowedPublicKeys | PyJWK | str | bytes = "",
algorithms: list[str] | None = None,
algorithms: Sequence[str] | None = None,
options: dict[str, Any] | None = None,
# deprecated arg, remove in pyjwt3
verify: bool | None = None,
Expand All @@ -111,7 +111,7 @@ def decode_complete(
# passthrough arguments to _validate_claims
# consider putting in options
audience: str | Iterable[str] | None = None,
issuer: str | List[str] | None = None,
issuer: str | Sequence[str] | None = None,
leeway: float | timedelta = 0,
# kwargs
**kwargs: Any,
Expand Down Expand Up @@ -187,7 +187,7 @@ def decode(
self,
jwt: str | bytes,
key: AllowedPublicKeys | PyJWK | str | bytes = "",
algorithms: list[str] | None = None,
algorithms: Sequence[str] | None = None,
options: dict[str, Any] | None = None,
# deprecated arg, remove in pyjwt3
verify: bool | None = None,
Expand All @@ -196,7 +196,7 @@ def decode(
# passthrough arguments to _validate_claims
# consider putting in options
audience: str | Iterable[str] | None = None,
issuer: str | List[str] | None = None,
issuer: str | Sequence[str] | None = None,
leeway: float | timedelta = 0,
# kwargs
**kwargs: Any,
Expand Down Expand Up @@ -363,7 +363,7 @@ def _validate_iss(self, payload: dict[str, Any], issuer: Any) -> None:
if "iss" not in payload:
raise MissingRequiredClaimError("iss")

if isinstance(issuer, list):
if isinstance(issuer, Sequence):
if payload["iss"] not in issuer:
raise InvalidIssuerError("Invalid issuer")
else:
Expand Down