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

Improve jwcrypto #13715

Merged
merged 3 commits into from
Mar 25, 2025
Merged

Improve jwcrypto #13715

merged 3 commits into from
Mar 25, 2025

Conversation

donBarbos
Copy link
Contributor

No description provided.

This comment has been minimized.

Copy link
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.

Thanks, one note about overloads below.

Comment on lines 107 to 112
@overload
def export(self, private_key: bool = True, as_dict: Literal[False] = ...) -> str: ...
@overload
def export(self, private_key: bool = True, as_dict: Literal[True] = ...) -> dict[str, Any]: ...
@overload
def export(self, private_key: bool = True, as_dict: bool = False) -> str | dict[str, Any]: ...
Copy link
Collaborator

Choose a reason for hiding this comment

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

Considering that the default is False, the first overload should just use that as default.

The second overload currently technically matches if someone doesn't provide the as_dict argument. We should skip the default. Unfortunately, just skipping it leads to a Python syntax error, which is why we need two overloads instead. (See overloads 2 and 3 in the suggestion below.)

I'd skip the third "fallback" overload, as the other overloads theoretically cover all cases. It's unlikely (though possible) that someone passes a bool variable or argument to this.

Suggested change
@overload
def export(self, private_key: bool = True, as_dict: Literal[False] = ...) -> str: ...
@overload
def export(self, private_key: bool = True, as_dict: Literal[True] = ...) -> dict[str, Any]: ...
@overload
def export(self, private_key: bool = True, as_dict: bool = False) -> str | dict[str, Any]: ...
@overload
def export(self, private_key: bool = True, as_dict: Literal[False] = False) -> str: ...
@overload
def export(self, private_key: bool, as_dict: Literal[True]) -> dict[str, Any]: ...
@overload
def export(self, *, as_dict: Literal[True]) -> dict[str, Any]: ...

The same for the other "export" methods below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated overload but left type hints : bool for other export_* functions that don't have other arguments

I think it won't hurt

Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@srittau srittau merged commit 8d67718 into python:main Mar 25, 2025
43 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