Skip to content

__ctype_{be,le}__ attributes missing for ctypes.c_*_complex types #148464

Closed

Description

@jorenham

Bug report

Bug description:

I was working on adding support for the fancy new complex ctypes types to numpy.ctypeslib 1, but ran into the problem that the c_{float,double,longdouble}_complex types do not have the __ctype_{be,le}__ attributes that e.g. their non-complex counterparts have:

>>> import ctypes as ct
>>> ct.c_float.__ctype_le__
<class 'ctypes.c_float'>
>>> ct.c_float_complex.__ctype_le__
Traceback (most recent call last):
  File "<python-input-2>", line 1, in <module>
    ct.c_float_complex.__ctype_le__
AttributeError: type object 'c_float_complex' has no attribute '__ctype_le__'

I checked Python 3.14.4 and 3.15.0a8.

CPython versions tested on:

3.14

Operating systems tested on:

Linux

Linked PRs

Footnotes

  1. NumPy relies on these attributes when converting e.g. numpy.dtype(">d") to ctypes.c_double.__ctype_be__ using numpy.ctypeslib.as_ctypes_type (docs). ↩

Activity

  1. self-assigned this
    on Apr 13, 2026
  2. skirpichev commented on Apr 13, 2026

    @skirpichev
    Member

    c_longdouble_complex

    Note, that these attributes are not available on c_longdouble as well. I don't see how we can change this.

  3. added a commit that references this issue on Apr 13, 2026
  4. removed their assignment
    on Apr 13, 2026
  5. added a commit that references this issue on Apr 13, 2026
  6. jorenham commented on Apr 13, 2026

    @jorenham
    Author

    c_longdouble_complex

    Note, that these attributes are not available on c_longdouble as well. I don't see how we can change this.

    Eh, long double sucks anyway 😛. I'm already happy that you're able to fix the complex float and double cases.

  7. added a commit that references this issue on Apr 17, 2026
  8. added a commit that references this issue on Apr 17, 2026
  9. vstinner commented on Apr 17, 2026

    @vstinner
    Member

    @skirpichev:

    Note, that these attributes are not available on c_longdouble as well. I don't see how we can change this.

    I'm curious. Is it because Python doesn't provide PyFloat_Pack8()/PyFloat_Unpack8() functions for long double?

  10. skirpichev commented on Apr 17, 2026

    @skirpichev
    Member

    Yes, as there is not definite format for long doubles.

  11. added a commit that references this issue on Apr 23, 2026
  12. jorenham commented on Apr 23, 2026

    @jorenham
    Author

    Thanks all

  13. added a commit that references this issue on Apr 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    extension-modulesC modules in the Modules dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions