You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Remove check for float subclasses with nb_float == NULL in PyNumber_Float() ? #112636
I still not sure what is more correct. Should we remove the check for float subclasses without nb_float? Did I make a mistake when I deleted the check for int subclasses without nb_int? Both cases are pretty hypothetical now, but we can't change the code without reason, and I don't remember my reasoning.
Simple question: when it could be NULL? Clearly, this won't work for simple static types with tp_base set to PyFloat_Type (or it's subtype). Multiple inheritance?
Here is a minimal example, when nb_float == NULL condition could be triggered. (Let me know if you had in mind something simpler.) Should we support such scenario? I doubt.
>>> a = xxx(3.14)
>>> float(a) # nb_float == NULL is not triggered, due to inheritance
3.14
>>> a.break_it()
>>> float(a) # and only NOW this branch will work...
XXX
3.14
Edit: pr description was updated with this example.
Activity
pythongh-112636: remove check for float subclasses without nb_float
serhiy-storchaka commentedon Mar 22, 2024
I still not sure what is more correct. Should we remove the check for float subclasses without
nb_float? Did I make a mistake when I deleted the check for int subclasses withoutnb_int? Both cases are pretty hypothetical now, but we can't change the code without reason, and I don't remember my reasoning.cc @mdickinson
skirpichev commentedon Mar 23, 2024
Simple question: when it could be
NULL? Clearly, this won't work for simple static types withtp_baseset toPyFloat_Type(or it's subtype). Multiple inheritance?serhiy-storchaka commentedon Mar 26, 2024
You can create a float subclass in C and explicitly set
nb_floatto NULL.skirpichev commentedon May 14, 2024
@serhiy-storchaka, I think in this way we could break anything:)
Here is a minimal example, when
nb_float == NULLcondition could be triggered. (Let me know if you had in mind something simpler.) Should we support such scenario? I doubt.Subclass code:
Session example:
Edit: pr description was updated with this example.
skirpichev commentedon Nov 2, 2024
@serhiy-storchaka, I'm closing issue as well. Let me know if we should add a test for this.
PS: As noted in the pr #112637 (comment), the integer workaround shouldn't be restored.