| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
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.
|
With this change, the following example: from ctypes.util import struct
@struct
class Point:
x: 'invalid_name'now fails with NameError: Traceback (most recent call last):
File "/home/vstinner/python/main/ann.py", line 3, in <module>
@struct
^^^^^^
File "/home/vstinner/python/main/Lib/ctypes/util.py", line 576, in struct
return process_the_struct(class_or_none)
File "/home/vstinner/python/main/Lib/ctypes/util.py", line 515, in _process_struct
annotations = annotationlib.get_annotations(decorated_class, eval_str=True)
File "/home/vstinner/python/main/Lib/annotationlib.py", line 1078, in get_annotations
else eval(_rewrite_star_unpack(value), globals, locals)
~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<string>", line 1, in <module>
NameError: name 'invalid_name' is not defined
The traceback starts on line 3 of ann.py, which is where the bug occurs: the traceback is correct and useful. |
Sorry, something went wrong.
| 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.
Sorry, something went wrong.
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.
Sorry, something went wrong.
Sorry, something went wrong.
|
I found this bug while trying to convert ctypes.Structure structures to @ctypes.util.struct in Lib/_pyrepl/windows_console.py which uses from __future__ import annotations. |
Sorry, something went wrong.
|
@ctypes.util.wrap_dll_function() has the same bug: see PR gh-154042 which fixes it. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
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.