| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
CC @vstinner, does it make sense for you? |
Sorry, something went wrong.
>>> a.break_it() >>> float(a) # and only NOW this branch will work... XXX 3.14 I don't understand the example. float(a) does now return XXX? Or does it print XXX? Which part of the code prints XXX? |
Sorry, something went wrong.
Ah, that was just a debug print from the removed (by this pr) code. I've added a diff to description. The point is that to trigger that code - you must explicitly set nb_float field in the derived class to NULL. But in this way we can break everything! Can't you set nb_add to NULL in a float subclass? Easy! But CPython has enough code, which assuming that float subclasses have working arithmetic dunder methods. |
Sorry, something went wrong.
|
What is the behavior on this nb_float=NULL type with your change? Does return PyFloat_FromString(o) fail? |
Sorry, something went wrong.
It fails with TypeError (after you run first break_it()).
Yes, because o is not a subclass of str/bytes/etc. |
Sorry, something went wrong.
There was a problem hiding this comment.
This change is a backward incompatible change. You should document it in a NEWS entry.
Sorry, something went wrong.
|
Sorry, but I now think that we should rather return a fallback for integers. |
Sorry, something went wrong.
Ok, I did. News entry was missed just as in 31a6554 (dropped similar check in PyNumber_Long).
But why?! Should we check on same ground that an int subtype has nb_add field set? |
Sorry, something went wrong.
|
Because PyFloat_AsDouble() never fails for instances of float subclasses. It does not use nb_float in that case. |
Sorry, something went wrong.
|
In same way we can recover in case when float subtype sets e.g. nb_negative to NULL. I think such subtypes are broken and it's better to fail quickly. |
Sorry, something went wrong.
Co-authored-by: Victor Stinner <vstinner@python.org>
There is a difference, if nb_int is set to NULL, but nb_index is not broken (at least not NULL) - then we got an equivalent fallback with _PyLong_Copy, see: Lines 1403 to 1405 in 31516c9 and Lines 1446 to 1448 in 31516c9 I still think we shouldn't keep workarounds for broken subtypes. But if so, at least the nb_int workaround shouldn't be restored. |
Sorry, something went wrong.
|
Ok, I'm closing this. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
This condition could be triggered only in very special scenario, if users code explicitly override inherited nb_float value and set it to NULL: