[issue32794] PyNumber_Float counterpart that doesn't accept strings

2018-02-08 Thread Mark Dickinson
Mark Dickinson added the comment: > Maybe use PyNumber_Check() [...] Ah, that works. It reads better than the `PyFloat_AsDouble` solution, too, since it's far from obvious that `PyFloat_AsDouble` goes to the trouble to coerce a float-y thing to a float. I did some searching around to see if

[issue32794] PyNumber_Float counterpart that doesn't accept strings

2018-02-08 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: For converting a string to a float there is PyFloat_FromString(). So that this part of functionality of PyNumber_Float() is redundant. In long perspective it would be worth to deprecate it. -- ___ Python tracker

[issue32794] PyNumber_Float counterpart that doesn't accept strings

2018-02-08 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Maybe use PyNumber_Check() to distinguish these two cases? if (PyNumber_Check(obj)) return PyNumber_Float(obj); PyErr_SetString(PyExc_TypeError, "not a number"); return NULL; -- nosy: +serhiy.storchaka ___

[issue32794] PyNumber_Float counterpart that doesn't accept strings

2018-02-08 Thread Mark Dickinson
New submission from Mark Dickinson : Our abstract objects layer in the C-API includes PyNumber_Float [1], which is equivalent to a Python-level `float` call, including the behaviour of accepting strings. I'm not convinced that it's a particularly useful function: I suspect that it's more commo