Skip to content

docs: Correct ctypes examples and outdated descriptions - #161303

Merged
methane merged 1 commit into
python:mainfrom
methane:fix-doc-ctypes
Nov 4, 2026
Merged

methane merged 1 commit into
python:mainfrom
methane:fix-doc-ctypes

Conversation

@methane

@methane methane commented Nov 4, 2026

Copy link
Copy Markdown
Member
  • Restore the missing comma in Hello, World so the output matches the input string.
  • Clarify that _align_ specifies a minimum alignment; the previous wording incorrectly described it as a maximum.
  • Use pointer indexing in the locking example: assigning an integer to .contents raises TypeError, while indexing updates the shared memory.
  • Show bytes representations in the linked-list example to match Python 3 output.
  • Align the frozen-module explanation with the _PyImport_FrozenBootstrap table used by the example, and update the structure definition and package detection to use is_package.
  • Correct the c_char_p argument conversion description: it accepts bytes and does not implicitly encode str.
  • Replace the unused type code 'L' with 'q'; 'L' is used by c_ulong.
  • Remove the unfinished sentence fragment “These are the”.
  • Fix the anonymous-union example by forward-declaring TYPEDESC and assigning pointer instances rather than pointer types.
  • Correct bitfield extraction to shift right by bit_offset.
  • Document that a c_char_p return value becomes None for a NULL pointer, and remove the obsolete Unicode-return comment.
  • Remove sizeof() from the operations that finalize _fields_; querying the size does not prevent subsequent field assignment.

@methane methane added docs Documentation in the Doc dir skip issue skip news labels Nov 4, 2026
@methane methane added needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes labels Nov 4, 2026
@methane
methane requested a balanced review from Copilot November 4, 2026 08:50
@github-project-automation github-project-automation Bot moved this to Todo in Docs PRs Nov 4, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

There are no active review issues for the ctypes documentation updates.

No open issues 🎉

What changed in this PR

This documentation-only PR updates the ctypes reference to correct examples and align descriptions with current behavior.

Changes:

  • Fix example output, shared-memory pointer assignments, and anonymous-union construction.
  • Update frozen-module structure definitions and explanations.
  • Clarify alignment, argument and return conversions, type codes, field finalization, and bitfield extraction.
File Description
Doc/​library/​ctypes.rst Corrects runnable examples, outdated API descriptions, and documentation errors.

Review effort: Balanced

@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #35636997 | 📁 Comparing 7e8fe2f against main (405f127)

  🔍 Preview build  

1 file changed
± library/ctypes.html

@methane
methane merged commit 6fa6d09 into python:main Nov 4, 2026
46 checks passed
@methane
methane deleted the fix-doc-ctypes branch November 4, 2026 13:31
@miss-islington-app

Copy link
Copy Markdown

Thanks @methane for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14, 3.15.
🐍🍒⛏🤖

@github-project-automation github-project-automation Bot moved this from Todo to Done in Docs PRs Nov 4, 2026
@bedevere-app

bedevere-app Bot commented Nov 4, 2026

Copy link
Copy Markdown

GH-161312 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Nov 4, 2026
@bedevere-app

bedevere-app Bot commented Nov 4, 2026

Copy link
Copy Markdown

GH-161313 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Nov 4, 2026
methane added a commit that referenced this pull request Nov 4, 2026
(cherry picked from commit 6fa6d09)

Co-authored-by: Inada Naoki <songofacandy@gmail.com>
methane added a commit that referenced this pull request Nov 4, 2026
(cherry picked from commit 6fa6d09)

Co-authored-by: Inada Naoki <songofacandy@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation in the Doc dir skip issue skip news

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants