Title: Invalid "equivalents" of the complex type constructor in docs · Issue #109218 · python/cpython · GitHub
Open Graph Title: Invalid "equivalents" of the complex type constructor in docs · Issue #109218 · python/cpython
X Title: Invalid "equivalents" of the complex type constructor in docs · Issue #109218 · python/cpython
Description: The sphinx docs says: class complex(real=0, imag=0) [...] Return a complex number with the value real + imag*1j or convert a string or number to a complex number. [...] The docstring (btw it doesn't mention a string as an argument): >>> ...
Open Graph Description: The sphinx docs says: class complex(real=0, imag=0) [...] Return a complex number with the value real + imag*1j or convert a string or number to a complex number. [...] The docstring (btw it doesn'...
X Description: The sphinx docs says: class complex(real=0, imag=0) [...] Return a complex number with the value real + imag*1j or convert a string or number to a complex number. [...] The docstring (btw it doesn&...
Opengraph URL: https://github.com/python/cpython/issues/109218
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Invalid \"equivalents\" of the complex type constructor in docs","articleBody":"The sphinx docs says:\r\n```\r\nclass complex(real=0, imag=0)\r\n[...]\r\nReturn a complex number with the value real + imag*1j or convert a string or number to a complex number.\r\n[...]\r\n```\r\nThe docstring (btw it doesn't mention a string as an argument):\r\n```\r\n\u003e\u003e\u003e print(complex.__doc__)\r\nCreate a complex number from a real part and an optional imaginary part.\r\n\r\nThis is equivalent to (real + imag*1j) where imag defaults to 0.\r\n```\r\n\r\nThat wrong, e.g.:\r\n```pycon\r\n\u003e\u003e\u003e complex(0.0, -0.0)\r\n-0j\r\n\u003e\u003e\u003e 0.0 + (-0.0)*1j\r\n0j\r\n\u003e\u003e\u003e complex(-0.0, -0.0)\r\n(-0-0j)\r\n\u003e\u003e\u003e -0.0 + (-0.0)*1j\r\n(-0+0j)\r\n\u003e\u003e\u003e complex(-0.0, 0.0)\r\n(-0+0j)\r\n\u003e\u003e\u003e -0.0 + 0.0*1j\r\n0j\r\n```\r\n\r\n\u003cdetails\u003e\r\n\u003csummary\u003eHere is an attempt (patch) to solve, let me know if this is worth a PR:\u003c/summary\u003e\r\n\r\n```diff\r\ndiff --git a/Doc/library/functions.rst b/Doc/library/functions.rst\r\nindex d9974c6350..78b85658ef 100644\r\n--- a/Doc/library/functions.rst\r\n+++ b/Doc/library/functions.rst\r\n@@ -373,8 +373,8 @@ are always available. They are listed here in alphabetical order.\r\n .. class:: complex(real=0, imag=0)\r\n complex(string)\r\n\r\n- Return a complex number with the value *real* + *imag*\\*1j or convert a string\r\n- or number to a complex number. If the first parameter is a string, it will\r\n+ Create a complex number from a real part and an optional imaginary part\r\n+ or convert a string to a complex number. If the first parameter is a string, it will\r\n be interpreted as a complex number and the function must be called without a\r\n second parameter. The second parameter can never be a string. Each argument\r\n may be any numeric type (including complex). If *imag* is omitted, it\r\ndiff --git a/Objects/complexobject.c b/Objects/complexobject.c\r\nindex 0e96f54584..336b703233 100644\r\n--- a/Objects/complexobject.c\r\n+++ b/Objects/complexobject.c\r\n@@ -886,9 +886,8 @@ complex.__new__ as complex_new\r\n real as r: object(c_default=\"NULL\") = 0\r\n imag as i: object(c_default=\"NULL\") = 0\r\n\r\n-Create a complex number from a real part and an optional imaginary part.\r\n-\r\n-This is equivalent to (real + imag*1j) where imag defaults to 0.\r\n+Create a complex number from a real part and an optional imaginary part\r\n+or convert a string to a complex number.\r\n [clinic start generated code]*/\r\n\r\n static PyObject *\r\n```\r\n\u003c/details\u003e\r\n\r\n**Edit**:\r\nAnother instance of this issue is in the [cmath docs](https://docs.python.org/3/library/cmath.html#conversions-to-and-from-polar-coordinates):\r\n```rst\r\nA Python complex number ``z`` is stored internally using *rectangular*\r\nor *Cartesian* coordinates. It is completely determined by its *real\r\npart* ``z.real`` and its *imaginary part* ``z.imag``. In other\r\nwords::\r\n\r\n z == z.real + z.imag*1j\r\n```\r\nE.g.:\r\n```pycon\r\n\u003e\u003e\u003e from cmath import inf\r\n\u003e\u003e\u003e complex(0.0, inf)\r\ninfj\r\n\u003e\u003e\u003e 0.0 + inf*1j\r\n(nan+infj)\r\n```\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-119620\n* gh-119635\n* gh-119687\n* gh-119795\n* gh-119796\n* gh-119803\n* gh-119805\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/skirpichev","@type":"Person","name":"skirpichev"},"datePublished":"2023-09-10T08:47:17.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":11},"url":"https://github.com/109218/cpython/issues/109218"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:073e162a-5518-d009-add0-562d8c0fa6fe |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B0F4:3410DA:2BC96A2:391E688:696B73A8 |
| html-safe-nonce | 5ea4ad4a9c262e5bc49966c2e29df1a39603893da4881b0c919ae3fedd200d1a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMEY0OjM0MTBEQToyQkM5NkEyOjM5MUU2ODg6Njk2QjczQTgiLCJ2aXNpdG9yX2lkIjoiODg5ODA0NDYyNTQ4MTg1NTkxMiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 32582e596bf7283d95f5b459ce36409754ac216a3fa84832594829a8c59cd477 |
| hovercard-subject-tag | issue:1889054796 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/109218/issue_layout |
| twitter:image | https://opengraph.githubassets.com/6c9d2775269bb70c6d56bdf38f2771ca20d6c8d03a3659d40e0356e1a16cfb62/python/cpython/issues/109218 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/6c9d2775269bb70c6d56bdf38f2771ca20d6c8d03a3659d40e0356e1a16cfb62/python/cpython/issues/109218 |
| og:image:alt | The sphinx docs says: class complex(real=0, imag=0) [...] Return a complex number with the value real + imag*1j or convert a string or number to a complex number. [...] The docstring (btw it doesn'... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | skirpichev |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5f99f7c1d70f01da5b93e5ca90303359738944d8ab470e396496262c66e60b8d |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 82560a55c6b2054555076f46e683151ee28a19bc |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width