Get the recursion depth of the caller function. In the __main__ module, at the module level, it should be 1.
()
| 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. |
| 2474 | |
| 2475 | In the __main__ module, at the module level, it should be 1. |
| 2476 | """ |
| 2477 | try: |
| 2478 | import _testinternalcapi |
| 2479 | depth = _testinternalcapi.get_recursion_depth() |
| 2480 | except (ImportError, RecursionError) as exc: |
| 2481 | # sys._getframe() + frame.f_back implementation. |
| 2482 | try: |
| 2483 | depth = 0 |
| 2484 | frame = sys._getframe() |
| 2485 | while frame is not None: |
| 2486 | depth += 1 |
| 2487 | frame = frame.f_back |
| 2488 | finally: |
| 2489 | # Break any reference cycles. |
| 2490 | frame = None |
| 2491 | |
| 2492 | # Ignore get_recursion_depth() frame. |
| 2493 | return max(depth - 1, 1) |
| 2494 | |
| 2495 | def get_recursion_available(): |
| 2496 | """Get the number of available frames before RecursionError. |
no outgoing calls
no test coverage detected
searching dependent graphs…