[mypyc] feat: unwrap NewType types to their base types for optimized code paths#19497
Merged
ilevkivskyi merged 18 commits intopython:masterfrom Aug 3, 2025
Merged
[mypyc] feat: unwrap NewType types to their base types for optimized code paths#19497ilevkivskyi merged 18 commits intopython:masterfrom
ilevkivskyi merged 18 commits intopython:masterfrom
Conversation
Contributor
Author
|
I'm just going to.... revert my change to the count() test so all of my tests pass and I get a green check on the PRs page I don't think this count() issue implies an issue with the PR because all of the other string methods generate their C code properly. |
Contributor
Author
|
I actually figured out last night how to fix the fixtures, so I'll do that instead for the sake of completeness |
Contributor
Author
|
Is there a good way to define MyStr once at the top and reuse it in each of the test cases? The current state is good enough but feels a bit cluttered for my liking. Unsure if an issuse. |
Contributor
Author
|
@brianschubert updated accordingly |
Contributor
Author
|
@ilevkivskyi could I trouble you for a review on this one as well? Its a relatively small PR. |
for more information, see https://pre-commit.ci
0bfdc86 to
63398e4
Compare
ilevkivskyi
reviewed
Aug 3, 2025
ilevkivskyi
reviewed
Aug 3, 2025
ilevkivskyi
approved these changes
Aug 3, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds special case logic for unwrapping NewType types to their actual type. This logic is currently working. a
NewType("name", str)now generates the same code as astr.I wasn't entirely sure of the best way to test this, so I just tweaked the str tests to use a union of str and newtype str and validated that the IR still uses
strand notobjectAlmost all of my tests are running fine, but I get a strange mypy error in the str.count tests saying that
strobjects do not have a .count method? Of course a str object has a .count method. Do you think this might related to the typeshed stuff again?