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
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ This project adheres to `Semantic Versioning <https://semver.org/>`__.
Changed
~~~~~~~

- Use ``Sequence`` for parameter types rather than ``List`` where applicable by @imnotjames in `#970 <https://github.com/jpadilla/pyjwt/pull/970>`__

Fixed
~~~~~

Expand Down
9 changes: 5 additions & 4 deletions jwt/api_jws.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import binascii
import json
import warnings
from collections.abc import Sequence
from typing import TYPE_CHECKING, Any

from .algorithms import (
Expand Down Expand Up @@ -30,7 +31,7 @@ class PyJWS:

def __init__(
self,
algorithms: list[str] | None = None,
algorithms: Sequence[str] | None = None,
options: dict[str, Any] | None = None,
) -> None:
self._algorithms = get_default_algorithms()
Expand Down Expand Up @@ -174,7 +175,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,
detached_payload: bytes | None = None,
**kwargs,
Expand Down Expand Up @@ -219,7 +220,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,
detached_payload: bytes | None = None,
**kwargs,
Expand Down Expand Up @@ -291,7 +292,7 @@ def _verify_signature(
header: dict[str, Any],
signature: bytes,
key: AllowedPublicKeys | PyJWK | str | bytes = "",
algorithms: list[str] | None = None,
algorithms: Sequence[str] | None = None,
) -> None:
if algorithms is None and isinstance(key, PyJWK):
algorithms = [key.algorithm_name]
Expand Down
14 changes: 7 additions & 7 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 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
Loading