FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-153903: Fix ctypes wrap_dll_function() with string annotations by vstinner · Pull Request #154042 · python/cpython · GitHub

Repository navigation

gh-153903: Fix ctypes wrap_dll_function() with string annotations - #154042

Merged
vstinner merged 1 commit into
python:mainfrom
vstinner:main
Jul 19, 2026
Merged

vstinner merged 1 commit into
python:mainfrom
vstinner:main

Conversation

vstinner commented Jul 19, 2026 •
edited by bedevere-app Bot
Loading

Copy link
Copy Markdown
Member

Call get_annotations() with eval_str=True.

Copy link
Copy Markdown
Member Author

@ctypes.util.struct has the same bug: see PR gh-154040 which fixes it.

Copy link
Copy Markdown
Member Author

cc @ZeroIntensity

Copy link
Copy Markdown
Member Author

With this change, the following example:

import ctypes.util

@ctypes.util.wrap_dll_function(ctypes.pythonapi)
def Py_GetVersion() -> 'invalid return type':
    ...

now fails with SyntaxError:

Traceback (most recent call last):
  File "/home/vstinner/python/main/ann.py", line 3, in <module>
    @ctypes.util.wrap_dll_function(ctypes.pythonapi)
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
  File "/home/vstinner/python/main/Lib/ctypes/util.py", line 582, in decorator
    annotations = annotationlib.get_annotations(func, 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
    invalid return type
            ^^^^^^
SyntaxError: invalid syntax

Hopefully, the traceback starts at line 3 of ann.py which is the line creating Py_GetVersion(), so the traceback is correct and helpful!

vstinner merged commit d5eb312 into python:main Jul 19, 2026
56 checks passed

Copy link
Copy Markdown
Member Author

Merged, thanks for the review.

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL