Repository navigation
[mypyc] Fix segfault from annotations naming classes that don't exist… - #22129
Merged
Merged
Conversation
Contributor
Author
|
@JukkaL Sorry for all the PRs but I use mypyc for a couple projects of mine, and they seem to be good test benches. I found a number of bugs when writing them that I've been fixing, and also I'm trying to squeeze as much performance as possible by looking for inefficiencies. Definitely feel free to take your time with them. If there is anything I can do to help or make the process easier, let me know. Also I generally tried to keep my changes small and targeted, though some of them kind of got out of hand... so if you think any should be replaced with deeper structural fixes, also let me know and we can close them. Sorry again, and thanks! |
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.
Fixes mypyc/mypyc#1209.
mypyc rebuilds
__annotations__for dataclasses, attrs classes and non-native classes. For an annotation naming a compiled class, it loads that class's type object, but a compiled class doesn't exist until its class statement has run, so the type object can still be NULL. Storing the NULL in__annotations__segfaulted at import. This happens when:TYPE_CHECKING(the case in the issue), orNow mypyc checks for NULL and stores the class's full name as a string instead, as it already does for a forward reference to a class later in the same module. With
from __future__ import annotations, Python doesn't evaluate these annotations either. If the class does exist (for example because its module was imported first), the annotation is still the class itself.