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

Make type name patterns explicit where typing. qualification is optional #267

Merged
merged 1 commit into from
Oct 14, 2024

Conversation

atifaziz
Copy link
Contributor

@atifaziz atifaziz commented Oct 13, 2024

This was a little hard to parse, is somewhat fragile and potentially allocates:

return pythonType.Name.Replace("typing.", "") switch

This PR proposes to use explicit or patterns instead for the following benefits (in order of importance):

  • Clear and explicit cases of what's accepted, e.g. "typing.Dict" or "Dict"
  • typing. isn't just removed anywhere in the name (always a prefix) to avoid accidental matches
  • No new string allocation in case Replace the effect of removing the string

I added tests for cases that were previously uncovered to make sure nothing was broken by this PR (unless I got the intent wrong).

@aaronpowell aaronpowell merged commit 7a18e2e into tonybaloney:main Oct 14, 2024
37 checks passed
@atifaziz atifaziz deleted the type-patterns branch October 14, 2024 05:43
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