-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
[mypyc] Fix __dict__ in CPython 3.11 #13206
Conversation
mypyc/codegen/emitclass.py
Outdated
@@ -18,6 +19,7 @@ | |||
from mypyc.sametype import is_same_type | |||
from mypyc.namegen import NameGenerator | |||
|
|||
PY_3_11 = sys.version_info >= (3, 11) |
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.
I think this isn't right: the running version of Python doesn't necessarily equal the version used at runtime. Maybe we need to emit #ifdef'ed C code instead?
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.
Oh right. Yeah my bad.
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.
Currently mypyc does not support cross Python version compilation, but yes conditional C code is probably better since cross version compilation is indeed a future goal. The Emitter class does have the capi_version
attribute for future reference (it's currently always set to the running version of Python, could be changed down the road).
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.
For some reason the PY_VERSION_HEX
checks are not working (I suspect the appropriate headers aren't being included properly). So for now I'm using capi_version
and leaving TODO
s to use PY_VERSION_HEX
in the future.
I have no clue how/why everything is now segfaulting. |
A second pair of eyes on the C code would be much appreciated :). |
🎉 All the tests are green. |
This fix will only work in 3.11b5 and above. It does not work for 3.11b4. So I'm waiting for GH actions/setup-python to update to 3.11b5. |
How do I make the CI use 3.11b5? @JelleZijlstra or @ichard26 do you have any idea? |
I think it requires actions/python-versions#180 to be merged |
This should now be ready. Thanks to everyone involved! |
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.
Not a mypyc expert but C code LGTM. I left one nit for you to consider.
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.
Thank you! Looks like the run against Python 3.11b5 happened and this has fixed testProtocol
and testPickling
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.
Thanks, after reading python/cpython#92678 this makes sense to me. I'll leave open for a couple days in case anyone else more familiar with mypyc or CPython wants to chime in :-)
We don't need this anymore. It was fixed upstream in CPython 3.11. |
Hm, @Fidget-Spinner I think we may still need this PR to fix The test fails because of |
Sorry but I'll be busy the next week, so I don't think I can work on this anytime soon. I give full consent to copy my code in this PR for use in your PR. Just attribute it with Co-Authored-By if you do use it please. |
@Fidget-Spinner I tried and it looks like this approach doesn't work. The problem is that Since this used to work until 3.10, it would be great if there was a reasonable way to support this in 3.11, does anyone have any ideas? |
Actually after looking a bit more at this, I don't think I understand what is going on here. A simple repro mypyc test case is
This raises an Note that assigning attributes on @msullivan Maybe you will have time to look at this to figure out what is going on here? |
OK, so my guess was right, since If this hack gets us through 3.11 this is fine probably, since 3.12 already includes good public APIs to work with managed dicts. |
Fixes mypyc/mypyc#943.
Many thanks to @kumaraditya303 for pointing me in the right direction.