gh-104533: Fix ctypes test_pointer_proto_missing_argtypes_error() (#154169)

vstinner <[email protected]>
Newsgroups gmane.comp.python.cvs
Message-ID <[email protected]>
https://github.com/python/cpython/commit/da5713c489c63622c0fdd25343a7ea7293a66e68
commit: da5713c489c63622c0fdd25343a7ea7293a66e68
branch: main
author: Victor Stinner <[email protected]>
committer: vstinner <[email protected]>
date: 2026-07-19T16:24:12Z
summary:

gh-104533: Fix ctypes test_pointer_proto_missing_argtypes_error() (#154169)

Save/restore Py_GetVersion.argtypes, since Py_GetVersion is used in
another test.

files:
M Lib/test/test_ctypes/test_pointers.py

diff --git a/Lib/test/test_ctypes/test_pointers.py b/Lib/test/test_ctypes/test_pointers.py
index 771cc8fbe0ec93..78480af34474a5 100644
--- a/Lib/test/test_ctypes/test_pointers.py
+++ b/Lib/test/test_ctypes/test_pointers.py
@@ -11,6 +11,7 @@
                     c_long, c_ulong, c_longlong, c_ulonglong,
                     c_float, c_double)
 from ctypes import _pointer_type_cache, _pointer_type_cache_fallback
+from test import support
 from test.support import import_helper
 from weakref import WeakSet
 _ctypes_test = import_helper.import_module("_ctypes_test")
@@ -409,10 +410,9 @@ class BadType(ctypes._Pointer):
             pass
 
         func = ctypes.pythonapi.Py_GetVersion
-        func.argtypes = (BadType,)
-
-        with self.assertRaises(ctypes.ArgumentError):
-            func(object())
+        with support.swap_attr(func, 'argtypes', (BadType,)):
+            with self.assertRaises(ctypes.ArgumentError):
+                func(object())
 
 class PointerTypeCacheTestCase(unittest.TestCase):
     # dummy tests to check warnings and base behavior

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.