Accept any Collection for algorithms, not just list#98
Merged
Conversation
The `algorithms` argument is only ever tested with truthiness and the `in` operator (it is stored verbatim as `self.allowed` on the JWS/JWE registries), so a tuple, set, or frozenset works at runtime. Widen the type hint from `list[str] | None` to `Collection[str] | None` across the jwt/jws/jwe public APIs and the registry constructors, and add a regression test covering list/tuple/set/frozenset.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #98 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 47 47
Lines 2930 2935 +5
Branches 340 340
=========================================
+ Hits 2930 2935 +5
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
lepture
approved these changes
May 21, 2026
jonathangreen
added a commit
to ThePalaceProject/circulation
that referenced
this pull request
May 27, 2026
joserfc 1.6.7 includes the upstream fix from authlib/joserfc#98, so the jwt.decode algorithms arg-type ignore is no longer needed and mypy now flags it as unused.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
Thank you for the great library 🙇🏻! We use it in a project I work on (https://github.com/ThePalaceProject/circulation). I was migrating from
authlibtojoserfc(in ThePalaceProject/circulation#3371) and I tried to pass afrozensetof algorithms intojwt.decode, which gave me a type error.Looking through the code, it looks like any
Collectionwill work, not just a list, so I made this small PR to widen the type hint and added tests covering additional collection types. This ended up being a bit bigger than I expected, since I had to thread the type hint through, but I think it's a helpful improvement for library consumers.Changes
algorithmsparameter type toCollection[str] | Noneinjwt.py,jws.py,jwe.py, and the JWS/JWE registry constructors.list/tuple/set/frozenset, and confirm a disallowed algorithm passed as a non-list collection still raisesUnsupportedAlgorithmError.