-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Improve jwcrypto
#13715
Conversation
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this 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.
stubs/jwcrypto/jwcrypto/jwk.pyi
Outdated
@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]: ... |
There was a problem hiding this comment.
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.
@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.
There was a problem hiding this comment.
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
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
No description provided.