GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — ctypes: Deprecate SetPointerType() and ARRAY() functions · Issue #105733 · python/cpython

ctypes: Deprecate SetPointerType() and ARRAY() functions #105733

New issue
Copy link
New issue
Copy link
Closed
Closed
ctypes: Deprecate SetPointerType() and ARRAY() functions#105733
Copy link
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-ctypestype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@vstinner
vstinner
opened on Jun 13, 2023
Issue body actions

The ctypes module has two undocumented functions: SetPointerType() and ARRAY(). These functions are marked as XXX Deprecated, but only in comments.

I propose to deprecate ctypes.SetPointerType() and ctypes.ARRAY() by emitting a DeprecationWarning warning.

These functions are not documented and not used in Python, but there are tested.

Linked PRs

  • gh-105733: Deprecate ctypes SetPointerType() and ARRAY() #105734
  • gh-105733: Fix ctypes What's New entry #106576
  • gh-105733: Soft-deprecate ctypes.ARRAY, rather than hard-deprecating it. #122281
  • [3.13] gh-105733: Soft-deprecate ctypes.ARRAY, rather than hard-deprecating it. (GH-122281) #122440

Activity

  1. vstinner
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Jun 13, 2023
  2. vstinner
    added 3 commits that reference this issue on Jun 13, 2023

    pythongh-105733: Deprecate ctypes SetPointerType() and ARRAY()

    bc0a349

    pythongh-105733: Deprecate ctypes SetPointerType() and ARRAY()

    0be4ba0

    gh-105733: Deprecate ctypes SetPointerType() and ARRAY() (#105734)

    2211454
  3. vstinner
    closed this as completedon Jun 13, 2023
  4. vstinner
    added 2 commits that reference this issue on Jul 9, 2023

    pythongh-105733: Fix ctypes What's New entry

    3ba9ee9

    gh-105733: Fix ctypes What's New entry (#106576)

    970982e
  5. hroncok
    added a commit that references this issue on Nov 20, 2023

    MAINT: Replace deprecated ctypes.ARRAY(item_type, size) with item_typ…

    d915524
  6. encukou commented on Jul 25, 2024

    @encukou
    encukou
    on Jul 25, 2024
    Member
    More actions

    I disagree with the proposal. (And with taking one hour between a proposal and merge.)

    The plan to remove ARRAY in 3.15 goes against PEP 387:

    If the expected maintenance overhead and security risk of the deprecated behavior is small (e.g. an old function is reimplemented in terms of a new, more general one), it can stay indefinitely (or until the situation changes).

    (I'll note that this clarification got added a few days after this proposal, though.)

    The function is two lines long, and has tests. It has no maintenance overhead or additional security risk.
    It's also used in third-party projects (some of which test with alphas/betas and have now switched to multiplication).

    I propose to restore it and soft-deprecate instead. Would you be OK with that, @vstinner?


    As for SetPointerType, yeah, no one should be using that, and hardly anyone is.

  7. encukou
    reopened this on Jul 25, 2024
  8. encukou commented on Jul 25, 2024

    @encukou
    encukou
    on Jul 25, 2024
    Member
    More actions

    (anecdotally: at EuroPython I've seen a person use ARRAY in the REPL. This is not worth them re-learning how to make array types.)

  9. vstinner commented on Jul 27, 2024

    @vstinner
    vstinner
    on Jul 27, 2024
    MemberAuthor
    More actions

    I didn't see any complain about the deprecation apart from you. I don't see the benefits of keeping two ways to create an array. PEP 20 says:

    There should be one-- and preferably only one --obvious way to do it.

    A code search on PyPI top 7,500 projects only finds 2 lines:

    PYPI-2024-03-16/astroid-3.1.0.tar.gz: astroid-3.1.0/tests/brain/test_ctypes.py: ctypes.ARRAY(3, 2)
    PYPI-2024-03-16/pwntools-4.12.0.tar.gz: pwntools-4.12.0/pwnlib/adb/bootloader.py: imgarray = ctypes.ARRAY(img_info, self.num_images)
    

    The first one is stupid, ctypes.ARRAY(3, 2) returns 6... The first parameter must be a ctypes type, not an integer.

  10. picnixz commented on Jul 28, 2024

    @picnixz
    picnixz
    on Jul 28, 2024
    Member
    More actions

    There are a bit more usages on GitHub: https://github.com/search?q=%2F%28%3F-i%29ctypes%5C.ARRAY%5C%28%2F&type=code (but some of them are CPython but I found a bit more normal usages that are not 7 years old)

  11. encukou commented on Jul 29, 2024

    @encukou
    encukou
    on Jul 29, 2024
    Member
    More actions

    So it's PEP 20 against PEP 387, or your opinion against mine :(

  12. JelleZijlstra commented on Jul 29, 2024

    @JelleZijlstra
    JelleZijlstra
    on Jul 29, 2024
    Member
    More actions

    I would favor keeping ARRAY, since there is little maintenance cost involved and removing it would break at least some users.

  13. picnixz commented on Jul 29, 2024

    @picnixz
    picnixz
    on Jul 29, 2024
    Member
    More actions

    I personally like ARRAY because it tells you that are you are creating an array (visually speaking)

  14. vstinner commented on Jul 29, 2024

    @vstinner
    vstinner
    on Jul 29, 2024
    MemberAuthor
    More actions

    There are a bit more usages on GitHub: https://github.com/search?q=%2F%28%3F-i%29ctypes%5C.ARRAY%5C%28%2F&type=code

    Oh right. Let's keep ARRAY(). But I would suggest to simply remove the deprecation in this case, no need to soft deprecate it if we keep it.

  15. encukou commented on Jul 29, 2024

    @encukou
    encukou
    on Jul 29, 2024
    Member
    More actions

    I'm for soft deprectation, because it tells you which of the two ways to do it is the obvious one :)

  16. encukou
    added a commit that references this issue on Jul 30, 2024

    gh-105733: Soft-deprecate ctypes.ARRAY, rather than hard-deprecating …

    3833d27
  17. miss-islington
    added a commit that references this issue on Jul 30, 2024

    pythongh-105733: Soft-deprecate ctypes.ARRAY, rather than hard-deprec…

    7abb55c
  18. encukou
    added a commit that references this issue on Jul 30, 2024

    [3.13] gh-105733: Soft-deprecate ctypes.ARRAY, rather than hard-depre…

    a4c7eb5
  19. picnixz commented on Jul 30, 2024

    @picnixz
    picnixz
    on Jul 30, 2024
    Member
    More actions

    Closing since completed in #122281.

    Reacted by Petr Viktorin
  20. picnixz
    closed this as completedon Jul 30, 2024
  21. blhsing
    added a commit that references this issue on Aug 22, 2024

    pythongh-105733: Soft-deprecate ctypes.ARRAY, rather than hard-deprec…

    0414ab2
  22. picnixz
    added
    topic-ctypes
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    on May 11, 2025
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

    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-ctypestype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.