class_docstr: Context manager that ensures there are at least N free stackframes (for
  a reasonable value of N).
class_docstr_tok: ["Context","manager","that","ensures","there","are","at","least","N","free","stackframes","(","for","a","reasonable","value","of","N",")","."]
code: def __enter__(self):
      cur_depth = stack_depth_of_caller()
      self.old_maxdepth = sys.getrecursionlimit()
      # The default CPython recursionlimit is 1000, but pytest seems to bump
      # it to 3000 during test execution. Let's make it something reasonable:
      self.new_maxdepth = cur_depth + 2000
      # Because we add to the recursion limit, to be good citizens we also
      # add a check for unbounded recursion.  The default limit is typically
      # 1000/3000, so this can only ever trigger if something really strange
      # is happening and it's hard to imagine an
      # intentionally-deeply-recursive use of this code.
      assert cur_depth <= 1000, (
          "Hypothesis would usually add %d to the stack depth of %d here, "
          "but we are already much deeper than expected.  Aborting now, to "
          "avoid extending the stack limit in an infinite loop..."
          % (self.new_maxdepth - self.old_maxdepth, self.old_maxdepth)
      )
      sys.setrecursionlimit(self.new_maxdepth)
  
imports: import array
  import sys
  import warnings
  from random import Random
  from typing import Callable, Dict, Generic, Iterable, Iterator, List, Optional, Sequence, Tuple, TypeVar, Union, overload
  from hypothesis.errors import HypothesisWarning
label_desc: Use image node_id 1 for calling the ensure_free_stackframes obj's underlying member method code with example usage: obj.__enter__() without return types