Skip to content

[Authlib] Fix JsonWebKey.import_key typing#15766

Merged
srittau merged 2 commits into
python:mainfrom
Lazyuki:patch-1
May 11, 2026
Merged

[Authlib] Fix JsonWebKey.import_key typing#15766
srittau merged 2 commits into
python:mainfrom
Lazyuki:patch-1

Conversation

@Lazyuki
Copy link
Copy Markdown

@Lazyuki Lazyuki commented May 11, 2026

import_key's raw accepts everything that load_pem_key accepts. The function annotation even says Import a Key from bytes, string, PEM or dict yet it currently only supports dict type.

https://github.com/authlib/authlib/blob/a0b76fac3fa114d7759af2010546bfc332364b63/authlib/jose/rfc7517/jwk.py#L25-L41

Since the value of raw is passed down to load_pem_key, it should accept everything that function supports, which is defined in

raw: str | bytes | float | Iterable[SupportsIndex] | SupportsIndex | SupportsBytes | ReadableBuffer,

Lazyuki and others added 2 commits May 11, 2026 16:17
import_key's raw accepts everything that load_pem_key accepts.
@github-actions
Copy link
Copy Markdown
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

pandas (https://github.com/pandas-dev/pandas)
+ pandas/core/computation/ops.py:328: error: Need type annotation for "_binary_ops_dict" (hint: "_binary_ops_dict: dict[<type>, <type>] = ...")  [var-annotated]

Copy link
Copy Markdown
Collaborator

@srittau srittau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That function is (too) heavily overloaded ... Thanks!

@srittau srittau merged commit 38f334e into python:main May 11, 2026
42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants