Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Make PyComplex_RealAsDouble/ImagAsDouble use __complex__ #109598

Closed
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error
@skirpichev

Description

@skirpichev

The C-API docs says: "Return the real/imag part of op as a C double." But the real code looks like:

PyComplex_RealAsDouble(PyObject*op){if (PyComplex_Check(op)) {return ((PyComplexObject*)op)->cval.real;    }else {returnPyFloat_AsDouble(op);    }}

So, we assume instead that theop is a float-like class (a subtype of or something with a__float__ dunder method). Instead, we should look on the__complex__ method in theelse branch. This is an issue like#44670, I think.

Minor issue: these functions aren't tested, only indirectly withformat() (that will not trigger all possible cases).

Edit:
The currentPyComplex_ImagAsDouble() silently returns0.0 for all non-PyComplexObject objects (or subtypes of). I think it's a bug and we should return-1.0 instead and set the error indicator.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp