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

style: pipe operator for union type hints #173

Merged
merged 1 commit into from
Oct 31, 2024

Conversation

jhoward-lm
Copy link
Contributor

This PR updates union type annotations to use the PEP-604 pipe operator, changing type hints like this:

Optional[Union[str, Dict[str, str]]]

to this:

str | dict[str, str] | None

The changes were auto-generated by running pyupgrade --py38-plus src/packageurl/__init__.py. It switches to using built-in types dict and tuple rather than typing.Dict and typing.Tuple.

Miscellaneous

  • applied refactorings suggested by sourcery
    • assign-if-exp: replace if statements, e.g.:
       if isinstance(s, str):
           s_bytes = s.encode("utf-8")
       else:
           s_bytes = s
      with if expressions:
      s_bytes = s.encode("utf-8") if isinstance(s, str) else s
    • avoid-builtin-shadow: don't assign to builtin variable type (renames local variable type to type_ in PackageURL.from_string())
  • applied fixes suggested by ruff
    • RUF010: Use explicit conversion flag (change instances of f"{repr(value)}" to f"{value!r}")

@jhoward-lm
Copy link
Contributor Author

@tdruez @gruebel Here's the follow-on PR for what we discussed in this comment

@tdruez tdruez merged commit 6f38e3e into package-url:main Oct 31, 2024
19 checks passed
@jhoward-lm jhoward-lm deleted the pep-604-union-types branch October 31, 2024 06:12
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