Repository navigation
ENH: Port _rational_tests to the Limited API using heap types - #32174
Conversation
_rational_tests to the Limited API using heap types [WIP]_rational_tests to the Limited API using heap types
|
This PR is ready for review! |
prathamhole14
left a comment
There was a problem hiding this comment.
No tp_traverse because a rational holds two ints and no PyObject*, so it cannot be part of a cycle. Heap types normally want both, but that only leaks at interpreter teardown.
|
I think the failing test is unrelated, this PR is ready for review! |
|
This one is a bit more complicated and needs some C API knowledge because it does some migrating to heap types. @kumaraditya303, would you mind giving it a look? |
|
A few points for heap types:
|
…mited # Conflicts: # numpy/_core/meson.build
|
Thanks for the reviews @kumaraditya303! One thing worth flagging is I had to set And you were right about the flag check. Once these are GC types it's always true, so the branch is gone now. On point 3: agreed this is a regression the static type used to reject attribute injection. But |
You can |
0a24d2b to
949da72
Compare
949da72 to
255b236
Compare
ngoldbaum
left a comment
There was a problem hiding this comment.
What about a short test like this to make sure the heap type setup is working correctly?
@pytest.mark.thread_unsafe(reason="Relies on global gc state")
def test_rational_subclass_lifetime():
class R(rational):
pass
r = R(1, 2)
assert r == Rational(1, 2)
assert gc.is_tracked(r)
wr = weakref.Ref(R)
del R
gc.collect()
# the instance keeps a reference to its type
assert wr() is not None
del r
gc.collect()
assert wr() is None|
Thanks @prathamhole14! |
PR summary
Related to: #31913, #32451 and #32747
I will make the PR more verbose soon. I want to see if CI is okay with this.
Benchmark report: https://gist.github.com/prathamhole14/17d187d84837de39d190d7a7db0e0d03
AI Disclosure
In understanding things, and finding places where changes are required.