Skip to content

A paragraph in ctypes documentation refers to an example that is no longer present in the documentation #115091

Description

@ztane

Documentation

In ctypes documentation for 3.11 there was this excerpt in ctypes documentation:

ctypes can access values like this with the in_dll() class methods of the type. pythonapi is a predefined symbol giving access to the Python C api:

>>> opt_flag = c_int.in_dll(pythonapi, "Py_OptimizeFlag")
>>> print(opt_flag)
c_long(0)
>>>

If the interpreter would have been started with -O, the sample would have printed c_long(1), or c_long(2) if -OO would have been specified.

The example was rewritten for 3.12 to use the - probably more widely understood Py_Version instead:

ctypes can access values like this with the in_dll() class methods of the type. pythonapi is a predefined symbol giving access to the Python C api:

>>> version = ctypes.c_int.in_dll(ctypes.pythonapi, "Py_Version")
>>> print(hex(version.value))
0x30c00a0

However the last paragraph referring to the old example is still present:

If the interpreter would have been started with -O, the sample would have printed c_long(1), or c_long(2) if -OO would have been specified.

Linked PRs

Activity

  1. added
    docsDocumentation in the Doc dir
    on Feb 6, 2024
  2. added a commit that references this issue on Feb 26, 2024
  3. added a commit that references this issue on Feb 26, 2024
  4. added a commit that references this issue on Feb 26, 2024
  5. encukou commented on Feb 26, 2024

    @encukou
    Member

    Thanks for the catch!

  6. added a commit that references this issue on Mar 4, 2024
  7. added a commit that references this issue on Mar 25, 2024
  8. added a commit that references this issue on Apr 17, 2024
  9. added a commit that references this issue on Jan 22, 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

    docsDocumentation in the Doc dir

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions