mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
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:
parent
8303d32ff5
commit
94bee45dee
10 changed files with 242 additions and 46 deletions
11
Objects/clinic/complexobject.c.h
generated
11
Objects/clinic/complexobject.c.h
generated
|
|
@ -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]*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue