summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_capi.py
diff options
context:
space:
mode:
authorWenzel Jakob <wenzel.jakob@epfl.ch>2022-05-27 08:27:39 (GMT)
committerGitHub <noreply@github.com>2022-05-27 08:27:39 (GMT)
commit5e34b494a08015e9b5a3deade23943bdba284a93 (patch)
tree829c824df2d307b14d0cf9efc51e2bbfcca92589 /Lib/test/test_capi.py
parent20d30ba2ccf9182e4f08db112f428c909148a40b (diff)
downloadcpython-5e34b494a08015e9b5a3deade23943bdba284a93.zip
cpython-5e34b494a08015e9b5a3deade23943bdba284a93.tar.gz
cpython-5e34b494a08015e9b5a3deade23943bdba284a93.tar.bz2
gh-60074: add new stable API function PyType_FromMetaclass (GH-93012)
Added a new stable API function ``PyType_FromMetaclass``, which mirrors the behavior of ``PyType_FromModuleAndSpec`` except that it takes an additional metaclass argument. This is, e.g., useful for language binding tools that need to store additional information in the type object.
Diffstat (limited to 'Lib/test/test_capi.py')
-rw-r--r--Lib/test/test_capi.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/Lib/test/test_capi.py b/Lib/test/test_capi.py
index 49cd821..95930ba 100644
--- a/Lib/test/test_capi.py
+++ b/Lib/test/test_capi.py
@@ -605,6 +605,19 @@ class CAPITest(unittest.TestCase):
del obj.value
self.assertEqual(obj.pvalue, 0)
+ def test_heaptype_with_custom_metaclass(self):
+ self.assertTrue(issubclass(_testcapi.HeapCTypeMetaclass, type))
+ self.assertTrue(issubclass(_testcapi.HeapCTypeMetaclassCustomNew, type))
+
+ t = _testcapi.pytype_fromspec_meta(_testcapi.HeapCTypeMetaclass)
+ self.assertIsInstance(t, type)
+ self.assertEqual(t.__name__, "HeapCTypeViaMetaclass")
+ self.assertIs(type(t), _testcapi.HeapCTypeMetaclass)
+
+ msg = "Metaclasses with custom tp_new are not supported."
+ with self.assertRaisesRegex(TypeError, msg):
+ t = _testcapi.pytype_fromspec_meta(_testcapi.HeapCTypeMetaclassCustomNew)
+
def test_pynumber_tobase(self):
from _testcapi import pynumber_tobase
self.assertEqual(pynumber_tobase(123, 2), '0b1111011')