GeezerVison is showing github.com — gh-125788: Improve ctypes error message for mismatched callback prototypes by aribaskagan · Pull Request #161873 · python/cpython
Conversation
aribaskagan
commented
Nov 12, 2026
•
edited by bedevere-app
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
When a CFUNCTYPE/WINFUNCTYPE callback is passed where a different callback prototype is expected, ctypes raised a confusing error because both prototype classes share the name CFunctionType:
ctypes.ArgumentError: argument 4: TypeError: expected CFunctionType instance instead of CFunctionType
This change makes CDataType_from_param_impl() report the expected and actual signatures when both sides are callback prototypes with argtypes set:
ctypes.ArgumentError: argument 4: TypeError: expected CFunctionType instance with signature (restype=<class 'ctypes.c_int'>, argtypes=(<class 'ctypes.c_void_p'>, <class 'ctypes.c_void_p'>)) instead of CFunctionType instance with signature (restype=<class 'ctypes.c_long'>, argtypes=(<class 'ctypes.c_void_p'>, <class 'ctypes.c_void_p'>))
Call behavior is unchanged; other mismatches keep the existing wording. Added test_mismatched_callback_prototype based on the qsort reproducer from the issue, plus a NEWS entry. ./python -m test test_ctypes passes on a Linux debug build.
AI assistance was used in preparing this change; I reviewed and tested it.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
chatgpt-codex-connector[bot] reacted with thumbs up emoji
… prototypes
CFUNCTYPE and WINFUNCTYPE prototypes are distinct classes that share one
type name, so a mismatch was reported as "expected CFunctionType instance
instead of CFunctionType". Include both signatures in the TypeError.
Co-authored-by: Kağan Arıbaş <[email protected]>
|
The following commit authors need to sign the Contributor License Agreement:

|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Codex Review Summary: ✅ Completed
This comment shows the latest Codex review activity on this pull request.
| Review |
Status |
Commit |
Review trigger |
| 📝 Code Review |
✅ Completed 2026-11-12T14:24:58.355484Z |
f6c92af |
PR opened |
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review" or "@codex security review".
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Thank you for your interest in contributing to Python. This is a community-driven project, and we want it to be a welcoming place to learn and collaborate.
Contributors are responsible for reviewing and understanding what they submit, checking its claims, and being able to explain changes in their own words. This helps reviewers focus on the contribution and leaves more time to support other contributors.
This contribution appears to have been authored with AI assistance. Please explain your contribution in your own words and describe how you checked its correctness.
Please read our guidelines for using AI tools.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|