Bug report
ctypes.util.test() calls cdll.load(...), which LibraryLoader does not have, so the self-test raises on Windows.
Where: Lib/ctypes/util.py, test() (line 535 on main), the Windows branch:
if os.name == "nt":
print(cdll.msvcrt)
print(cdll.load("msvcrt"))
LibraryLoader defines LoadLibrary, not load, and its __getattr__ turns the unknown name into an AttributeError.
Reproduce (Windows, 3.13.5; the line is the same on main, whose util.py already needs 3.15 syntax to import):
> python -c "import ctypes.util; ctypes.util.test()"
<CDLL 'msvcrt', handle 7ffd0a0b0000 at 0x...>
AttributeError: load
Proposed fix:
- print(cdll.load("msvcrt"))
+ print(cdll.LoadLibrary("msvcrt"))
Checked by running test() on Windows against 3.13.5's util.py: the current code raises AttributeError: load; the fixed code completes and prints the loaded CDLL.
Environment: Windows 11, CPython 3.13.5.
Found while auditing installed code with a verification tool I am building; the reproduction above was run on the version named, and the proposed fix was applied to a local copy and run as well. Report drafted with AI assistance.
Linked PRs
Bug report
ctypes.util.test()callscdll.load(...), whichLibraryLoaderdoes not have, so the self-test raises on Windows.Where:
Lib/ctypes/util.py,test()(line 535 onmain), the Windows branch:LibraryLoaderdefinesLoadLibrary, notload, and its__getattr__turns the unknown name into anAttributeError.Reproduce (Windows, 3.13.5; the line is the same on
main, whoseutil.pyalready needs 3.15 syntax to import):Proposed fix:
Checked by running
test()on Windows against 3.13.5'sutil.py: the current code raisesAttributeError: load; the fixed code completes and prints the loaded CDLL.Environment: Windows 11, CPython 3.13.5.
Found while auditing installed code with a verification tool I am building; the reproduction above was run on the version named, and the proposed fix was applied to a local copy and run as well. Report drafted with AI assistance.
Linked PRs
ctypes.util.test#157776