Check that given type cannot be instantiated using *args and **kwds. See bpo-43916: Add Py_TPFLAGS_DISALLOW_INSTANTIATION type flag.
(testcase, tp, *args, **kwds)
| 2384 | |
| 2385 | |
| 2386 | def check_disallow_instantiation(testcase, tp, *args, **kwds): |
| 2387 | """ |
| 2388 | Check that given type cannot be instantiated using *args and **kwds. |
| 2389 | |
| 2390 | See bpo-43916: Add Py_TPFLAGS_DISALLOW_INSTANTIATION type flag. |
| 2391 | """ |
| 2392 | mod = tp.__module__ |
| 2393 | name = tp.__name__ |
| 2394 | if mod != 'builtins': |
| 2395 | qualname = f"{mod}.{name}" |
| 2396 | else: |
| 2397 | qualname = f"{name}" |
| 2398 | msg = f"cannot create '{re.escape(qualname)}' instances" |
| 2399 | testcase.assertRaisesRegex(TypeError, msg, tp, *args, **kwds) |
| 2400 | testcase.assertRaisesRegex(TypeError, msg, tp.__new__, tp, *args, **kwds) |
| 2401 | |
| 2402 | def get_recursion_depth(): |
| 2403 | """Get the recursion depth of the caller function. |