-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
gh-109218: Deprecate weird cases in the complex() constructor #119620
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
9035969
c35779b
607e2d5
d7b2c2f
d7a9120
537cc4e
e8b6ba9
ddfed7b
9e66399
573b2cd
14598f0
90029cf
2a60cc8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -905,6 +905,16 @@ complex_subtype_from_string(PyTypeObject *type, PyObject *v) | |
| return result; | ||
| } | ||
|
|
||
| /* The constructor should only accept a string as a positional argument, | ||
| * not as by the 'real' keyword. But Argument Clinic does not allow | ||
| * to distinguish between argument passed positionally and by keyword. | ||
| * So the constructor must be split into two parts: actual_complex_new() | ||
| * handles the case of no arguments and one positional argument, and calls | ||
| * complex_new(), implemented with Argument Clinic, to handle the remaining | ||
| * cases: 'real' and 'imag' arguments. This separation is well suited | ||
| * for different constructor roles: convering a string or number to a complex | ||
| * number and constructing a complex number from real and imaginary parts. | ||
| */ | ||
| static PyObject * | ||
| actual_complex_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) | ||
| { | ||
|
|
@@ -993,6 +1003,8 @@ complex_new_impl(PyTypeObject *type, PyObject *r, PyObject *i) | |
| } | ||
| PyObject *orig_r = r; | ||
|
|
||
| /* DEPRECATED: The call of try_complex_special_method() for the "real" | ||
| * part will be dropped after the end of the deprecation period. */ | ||
| tmp = try_complex_special_method(r); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IIUIC, this logic will be dropped after a deprecation period as well. I'm not sure if this is obvious, maybe worth a comment. |
||
| if (tmp) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. else if (PyErr_Occurred()) branch is not tested. |
||
| r = tmp; | ||
|
|
@@ -1033,6 +1045,7 @@ complex_new_impl(PyTypeObject *type, PyObject *r, PyObject *i) | |
| both be treated as numbers, and the constructor should return a | ||
| complex number equal to (real + imag*1j). | ||
|
|
||
| The following is DEPRECATED: | ||
| Note that we do NOT assume the input to already be in canonical | ||
| form; the "real" and "imag" parts might themselves be complex | ||
| numbers, which slightly complicates the code below. */ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be worth adding a comment above this function explaining the purpose (and explaining why this is different from
complex_new)?