-
Notifications
You must be signed in to change notification settings - Fork 46
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
fix: qualifiers type annotation #172
Conversation
Signed-off-by: Jonathan Howard <[email protected]>
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.
looks good and locally it passes mypy
😄
@jhoward-lm I see there are still |
@tdruez I don't believe so. Those are generalized argument/parameter types, but the type gets narrowed before returning. You did however draw my attention to several other typing issues; I'll push a commit shortly for review |
Signed-off-by: Jonathan Howard <[email protected]>
Signed-off-by: Jonathan Howard <[email protected]>
Signed-off-by: Jonathan Howard <[email protected]>
@gruebel @tdruez So things like this could be updated across the board: # before
Union[str, Dict[str, str], None]
# after
str | dict[str, str] | None Let me know if you want me to go ahead with it, or I can hold off. |
I actually like the newer syntax style more than the old one, but I would recommend to do it in a follow-up PR, because it is kind of like formatting and I don't like to mix actual changes with formatting. |
@jhoward-lm there was no need for testing it with 3.7, because it was dropped with the last release. And CI passed already with your changes, so no need to do extra testing for this PR 😄 |
Signed-off-by: Jonathan Howard <[email protected]>
@tdruez @gruebel I threw together a quick branch on my fork to test caching for faster lookup. Basically repeated calls to If you're interested, let me know if you want me to create an issue or a draft PR for review. Tested with this against the current code and after implementing the caching: if __name__ == "__main__":
import timeit
def _test_parsing():
purl = PackageURL.from_string(
"pkg:deb/ubuntu/ca-certificates@20230311?arch=all&distro=lunar"
)
print("time:", timeit.timeit(stmt=_test_parsing)) Current code: ~12.8 seconds The results were a bit more dramatic when I tested with this: if __name__ == "__main__":
import timeit
def _test_parsing():
purl = PackageURL(
type="deb",
namespace="ubuntu",
name="ca-certificates",
version="20230311",
qualifiers="arch=all&distro=lunar",
subpath=None,
)
print("time:", timeit.timeit(stmt=_test_parsing)) Current code: ~5.9 seconds Previous test but with Current code: ~5.1 seconds |
@jhoward-lm All good, PR merged. Thanks for your contribution 👍 |
This PR modifies the type annotation of the
qualifiers
attribute declaration from:to:
in order to reflect its true runtime type.
Closes #169.
Miscellaneous
encode: "Optional[Literal[False]]"
overload ofnormalize_qualifiers
toDict[str, str]
encode: "Optional[Literal[False]]"
overload ofnormalize
toDict[str, str]
(the other tuple members in the return type unchanged)Union[AnyStr, Dict[str, str], None]
toOptional[Union[AnyStr, Dict[str, str]]]
Union[str, Dict[str, str], None]
toOptional[Union[str, Dict[str, str]]]
# NOQA
directivesPackageURL.__new__
andPackageURL.from_string
totyping_extensions.Self
PackageURL.__new__
fromself
tocls
since it is aclassmethod
from __future__ import annotations