-
Notifications
You must be signed in to change notification settings - Fork 792
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
Fix abi3
conversion of __complex__
classes
#3185
Conversation
b15573f
to
8e6b7dc
Compare
First time contributor has agreed to the new licensing scheme. |
I've pushed a couple more commits on the basis of the review. I'm happy to revert the descriptor-resolution commit and replace it just with a comment about similarity not equality to CPython's implementation, if you'd rather. edit: I think the CI failures should have been fixed by the merge of #3194. |
A minor procedural question: this PR is getting a little messy in commit history, and with the CI failures, needs to be updated over |
We certainly prefer a coherent story and have explicitly configured bors to not squash merges, so turning this back into two commits would be really helpful! |
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 expect for rebasing, this looks great now. Thank you again for following up on all the side quests.
Will wait a day or two before merging to see if any other maintainers have additional thoughts on this.
00577eb
to
b81dcba
Compare
No trouble - I've just rebased down to two commits. Just for visibility, there's a couple of my decisions that I think other maintainers might want to question:
|
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, the tests are great and I'm happy that the implementation is correct!
I have a couple of suggestions to round this off, I'm happy to see this merged when those are either addressed or dismissed.
As for visibility, I suggest we keep |
Well, I'm certainly glad that you mentioned More importantly, though, it made me realise that What course of action would you like here?
Fwiw, the complexity I'm finding here in correctly resolving non-slotted magic-method lookups across all Pythons strengthens the case for a central (All your other suggestions are easy and uncontentious to me.) |
I had already typed the "bors try" comment yesterday to give this a while with the full CI but then decided against spending the CPU time...
Personally, I would probably prefer this solution for now. We can always add more fast paths in the future and this variant does not commit us to any new API surface even in the FFI module. |
Yeah, I think that's what I'd have suggested if someone was contributing code on a project I maintained. I'll write this all up and push a couple of new commits to show what it looks like. Testing against older Pythons makes it look to me like I may have found a bug in (Sorry this has got super deep in the weeds - I wasn't expecting that! I can say that I'm having great fun learning way more about Python/CPython internals, though.) |
Please have a look at #2927 and #2891, maybe you hit one of those. |
b81dcba
to
8571c81
Compare
I've rebased this branch again with the changes suggested above. It appears to work for me on CPythons 3.7 to 3.11 with both versioned and stable APIs, but I wasn't able to test PyPy myself because the tests seem to segfault immediately for me (even on |
Let's give it a whirl in the CI then. bors try |
tryBuild succeeded! The publicly hosted instance of bors-ng is deprecated and will go away soon. If you want to self-host your own instance, instructions are here. If you want to switch to GitHub's built-in merge queue, visit their help page. |
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.
Nice one! I have just a couple of tiny code style suggestions for the new lookup_special
body, otherwise this looks perfect.
cargo test
on PyPy is known to not work, it's a deficiency on PyPy's side which I hope to resolve one day. We have a pytests
crate which builds an extension module and runs a small set of tests, which PyPy does support.
`PyAny::lookup_special` is an approximate equivalent to the CPython internal `_PyObject_LookupSpecial`, which is used to resolve lookups of "magic" methods. These are only looked up from the type, and skip the instance dictionary during the lookup. Despite this, they are still required to resolve the descriptor protocol. Many magic methods have slots on the `PyTypeObject` or respective subobjects, but these are not necessarily available when targeting the limited API or PyPy. In these cases, the requisite logic can be worked around using safe but likely slower APIs. Co-authored-by: David Hewitt <[email protected]> Fix up lookup-special
Python classes that were not `complex` but implemented the `__complex__` magic would have that method called via `PyComplex_AsCComplex` when running against the full API, but the limited-API version `PyComplex_RealAsDouble` does not attempt this conversion. If the input object is not already complex, we can call the magic before proceeding.
8571c81
to
8d98b42
Compare
There we go - style changes made.
Ah yeah, that'd explain it - I'll have a look at doing that properly next time round, thanks! |
I think this is good to go now having collected two approvals with all threads resolved. bors r+ |
Build succeeded! The publicly hosted instance of bors-ng is deprecated and will go away soon. If you want to self-host your own instance, instructions are here. If you want to switch to GitHub's built-in merge queue, visit their help page. |
Thanks for all the help, chaps! |
Python classes that were not
complex
but implemented the__complex__
magic would have that method called viaPyComplex_AsCComplex
when running against the full API, but the limited-API versionPyComplex_RealAsDouble
does not attempt this conversion. If the input object is not already complex, we can call the magic before proceeding.Happy to modify if I've made a mess of testing strategy - I'm not sure I've managed to do it in the same style as other tests.
Fix #3164.