◐ Shell
reader mode source ↗
Skip to content

gh-109218: Deprecate weird cases in the complex() constructor#119620

Merged
serhiy-storchaka merged 13 commits into
python:mainfrom
serhiy-storchaka:complex-constructor
May 30, 2024
Merged

gh-109218: Deprecate weird cases in the complex() constructor#119620
serhiy-storchaka merged 13 commits into
python:mainfrom
serhiy-storchaka:complex-constructor

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented May 27, 2024

Copy link
Copy Markdown
Member
  • Passing a string as the "real" keyword argument is now an error; it should only be passed as a single positional argument.
  • Passing a complex number as the real or imag argument is now deprecated; it should only be passed as a single positional argument.

📚 Documentation preview 📚: https://cpython-previews--119620.org.readthedocs.build/

* Passing a string as the "real" keyword argument is now an error;
  it should only be passed as a single positional argument.
* Passing a complex number as the *real* or *imag* argument is now deprecated;
  it should only be passed as a single positional argument.
* Share common classes.
* Use exactly representable floats and exact tests.
* Check the sign of zero components.
* Remove duplicated tests (mostly left after merging int and long).
* Reorder tests in more consistent way.
* Test more error messages.
* Add tests for missed cases.

@skirpichev skirpichev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hide comment

tmp == NULL condition on L1092 also now only partially covered.

Just checked coverage report after ./python -m test test_complex test_capi.test_complex

@serhiy-storchaka

Copy link
Copy Markdown
Member Author

Thank you for your review @skirpichev. Much of coverage is added by test added in #119635.

@mdickinson mdickinson left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hide comment

LGTM in principle, and works as expected in manual testing. I won't claim to have examined all the branching possibilities, but it looks as though @skirpichev is on top of that. :-)

@skirpichev skirpichev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hide comment

LGTM, except for useless PyComplex_Check() branch in the actual_complex_new() and one missing branch coverage here.

The rest, probably, not worth for improving, as it will be eventually removed. Though, I think that removing inaccessible cases (various own_r branches) will make code more readable.

@serhiy-storchaka serhiy-storchaka merged commit ef01e95 into python:main May 30, 2024
@serhiy-storchaka serhiy-storchaka deleted the complex-constructor branch May 30, 2024 20:31
noahbkim pushed a commit to hudson-trading/cpython that referenced this pull request Jul 11, 2024
…ythonGH-119620)

* Passing a string as the "real" keyword argument is now an error;
  it should only be passed as a single positional argument.
* Passing a complex number as the "real" or "imag" argument is now deprecated;
  it should only be passed as a single positional argument.
estyxx pushed a commit to estyxx/cpython that referenced this pull request Jul 17, 2024
…ythonGH-119620)

* Passing a string as the "real" keyword argument is now an error;
  it should only be passed as a single positional argument.
* Passing a complex number as the "real" or "imag" argument is now deprecated;
  it should only be passed as a single positional argument.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants