gh-84978: Add float.from_number() and complex.from_number() (GH-26827)

They are alternate constructors which only accept numbers
(including objects with special methods __float__, __complex__
and __index__), but not strings.
This commit is contained in:
Serhiy Storchaka 2024-07-15 19:07:00 +03:00 committed by GitHub
parent 8303d32ff5
commit 94bee45dee
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 242 additions and 46 deletions

View file

@ -160,4 +160,13 @@ skip_optional_pos:
exit:
return return_value;
}
/*[clinic end generated code: output=295ecfd71389d7fe input=a9049054013a1b77]*/
PyDoc_STRVAR(complex_from_number__doc__,
"from_number($type, number, /)\n"
"--\n"
"\n"
"Convert number to a complex floating-point number.");
#define COMPLEX_FROM_NUMBER_METHODDEF \
{"from_number", (PyCFunction)complex_from_number, METH_O|METH_CLASS, complex_from_number__doc__},
/*[clinic end generated code: output=188438cc9ae167f7 input=a9049054013a1b77]*/