MCPcopy Create free account
hub / github.com/RustPython/RustPython / StackSummary

Class StackSummary

Lib/traceback.py:434–791  ·  view source on GitHub ↗

A list of FrameSummary objects, representing a stack of frames.

Source from the content-addressed store, hash-verified

432
433
434class StackSummary(list):
435 """A list of FrameSummary objects, representing a stack of frames."""
436
437 @classmethod
438 def extract(klass, frame_gen, *, limit=None, lookup_lines=True,
439 capture_locals=False):
440 """Create a StackSummary from a traceback or stack object.
441
442 :param frame_gen: A generator that yields (frame, lineno) tuples
443 whose summaries are to be included in the stack.
444 :param limit: None to include all frames or the number of frames to
445 include.
446 :param lookup_lines: If True, lookup lines for each frame immediately,
447 otherwise lookup is deferred until the frame is rendered.
448 :param capture_locals: If True, the local variables from each frame will
449 be captured as object representations into the FrameSummary.
450 """
451 def extended_frame_gen():
452 for f, lineno in frame_gen:
453 yield f, (lineno, None, None, None)
454
455 return klass._extract_from_extended_frame_gen(
456 extended_frame_gen(), limit=limit, lookup_lines=lookup_lines,
457 capture_locals=capture_locals)
458
459 @classmethod
460 def _extract_from_extended_frame_gen(klass, frame_gen, *, limit=None,
461 lookup_lines=True, capture_locals=False):
462 # Same as extract but operates on a frame generator that yields
463 # (frame, (lineno, end_lineno, colno, end_colno)) in the stack.
464 # Only lineno is required, the remaining fields can be None if the
465 # information is not available.
466 builtin_limit = limit is BUILTIN_EXCEPTION_LIMIT
467 if limit is None or builtin_limit:
468 limit = getattr(sys, 'tracebacklimit', None)
469 if limit is not None and limit < 0:
470 limit = 0
471 if limit is not None:
472 if builtin_limit:
473 frame_gen = tuple(frame_gen)
474 frame_gen = frame_gen[len(frame_gen) - limit:]
475 elif limit >= 0:
476 frame_gen = itertools.islice(frame_gen, limit)
477 else:
478 frame_gen = collections.deque(frame_gen, maxlen=-limit)
479
480 result = klass()
481 fnames = set()
482 for f, (lineno, end_lineno, colno, end_colno) in frame_gen:
483 co = f.f_code
484 filename = co.co_filename
485 name = co.co_name
486 fnames.add(filename)
487 linecache.lazycache(filename, f.f_globals)
488 # Must defer line lookups until we have called checkcache.
489 if capture_locals:
490 f_locals = f.f_locals
491 else:

Callers 1

from_listMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected