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)
| 2454 | |
| 2455 | |
| 2456 | def check_disallow_instantiation(testcase, tp, *args, **kwds): |
| 2457 | """ |
| 2458 | Check that given type cannot be instantiated using *args and **kwds. |
| 2459 | |
| 2460 | See bpo-43916: Add Py_TPFLAGS_DISALLOW_INSTANTIATION type flag. |
| 2461 | """ |
| 2462 | mod = tp.__module__ |
| 2463 | name = tp.__name__ |
| 2464 | if mod != 'builtins': |
| 2465 | qualname = f"{mod}.{name}" |
| 2466 | else: |
| 2467 | qualname = f"{name}" |
| 2468 | msg = f"cannot create '{re.escape(qualname)}' instances" |
| 2469 | testcase.assertRaisesRegex(TypeError, msg, tp, *args, **kwds) |
| 2470 | testcase.assertRaisesRegex(TypeError, msg, tp.__new__, tp, *args, **kwds) |
| 2471 | |
| 2472 | def get_recursion_depth(): |
| 2473 | """Get the recursion depth of the caller function. |
searching dependent graphs…