MCPcopy Index your code
hub / github.com/python/cpython / check_disallow_instantiation

Function check_disallow_instantiation

Lib/test/support/__init__.py:2456–2470  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

2454
2455
2456def 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
2472def get_recursion_depth():
2473 """Get the recursion depth of the caller function.

Calls 2

escapeMethod · 0.80
assertRaisesRegexMethod · 0.80

Used in the wild real call sites across dependent graphs

searching dependent graphs…