Uh oh!
There was an error while loading. Please reload this page.
gh-104533: Fix @ctypes.util.struct with string annotations - #154040
Conversation
Fix @ctypes.util.struct on structures declared in a module which uses "from __future__ import annotations". The decorator now calls get_annotations() with eval_str=True.
vstinner
commented
Jul 19, 2026
With this change, the following example: fromctypes.utilimportstruct@structclassPoint:
x: 'invalid_name'now fails with The traceback starts on line 3 of |
| def test_string_annotations(self): | ||
| from test.test_ctypes import struct_str_ann | ||
| Point = struct_str_ann.Point | ||
| fields = [['x', c_int], ['y', c_int]] |
There was a problem hiding this comment.
This line should be updated if PR gh-154038 is merged first.
There was a problem hiding this comment.
Crap. I missed my own comment when I merged this PR, and now the pre-commit CI fails on the main branch :-( I wrote #154091 to fix the CI.
vstinner
commented
Jul 19, 2026
vstinner
commented
Jul 19, 2026
I found this bug while trying to convert |
vstinner
commented
Jul 19, 2026
|
Fix
@ctypes.util.structon structures declared in a module which usesfrom __future__ import annotations. The decorator now calls get_annotations() with eval_str=True.