@@ -240,7 +240,7 @@ def clear_frames(tb):
240240
241241
242242class FrameSummary :
243- """A single frame from a traceback.
243+ """Information about a single frame from a traceback.
244244
245245 - :attr:`filename` The filename for the frame.
246246 - :attr:`lineno` The line within filename for the frame that was
@@ -365,15 +365,15 @@ def _get_code_position(code, instruction_index):
365365_RECURSIVE_CUTOFF = 3 # Also hardcoded in traceback.c.
366366
367367class StackSummary (list ):
368- """A stack of frames."""
368+ """A list of FrameSummary objects, representing a stack of frames."""
369369
370370 @classmethod
371371 def extract (klass , frame_gen , * , limit = None , lookup_lines = True ,
372372 capture_locals = False ):
373373 """Create a StackSummary from a traceback or stack object.
374374
375- :param frame_gen: A generator that yields (frame, lineno) tuples to
376- include in the stack.
375+ :param frame_gen: A generator that yields (frame, lineno) tuples
376+ whose summaries are to be included in the stack.
377377 :param limit: None to include all frames or the number of frames to
378378 include.
379379 :param lookup_lines: If True, lookup lines for each frame immediately,
@@ -394,7 +394,7 @@ def _extract_from_extended_frame_gen(klass, frame_gen, *, limit=None,
394394 lookup_lines = True , capture_locals = False ):
395395 # Same as extract but operates on a frame generator that yields
396396 # (frame, (lineno, end_lineno, colno, end_colno)) in the stack.
397- # Only lineno is required, the remaining fields can be empty if the
397+ # Only lineno is required, the remaining fields can be None if the
398398 # information is not available.
399399 if limit is None :
400400 limit = getattr (sys , 'tracebacklimit' , None )
@@ -450,34 +450,38 @@ def from_list(klass, a_list):
450450 result .append (FrameSummary (filename , lineno , name , line = line ))
451451 return result
452452
453- def format_frame (self , frame ):
454- """Format the lines for a single frame .
453+ def format_frame_summary (self , frame_summary ):
454+ """Format the lines for a single FrameSummary .
455455
456456 Returns a string representing one frame involved in the stack. This
457457 gets called for every frame to be printed in the stack summary.
458458 """
459459 row = []
460460 row .append (' File "{}", line {}, in {}\n ' .format (
461- frame .filename , frame .lineno , frame .name ))
462- if frame .line :
463- row .append (' {}\n ' .format (frame .line .strip ()))
461+ frame_summary .filename , frame_summary .lineno , frame_summary .name ))
462+ if frame_summary .line :
463+ row .append (' {}\n ' .format (frame_summary .line .strip ()))
464464
465- stripped_characters = len (frame ._original_line ) - len (frame .line .lstrip ())
465+ orig_line_len = len (frame_summary ._original_line )
466+ frame_line_len = len (frame_summary .line .lstrip ())
467+ stripped_characters = orig_line_len - frame_line_len
466468 if (
467- frame .colno is not None
468- and frame .end_colno is not None
469+ frame_summary .colno is not None
470+ and frame_summary .end_colno is not None
469471 ):
470- colno = _byte_offset_to_character_offset (frame ._original_line , frame .colno )
471- end_colno = _byte_offset_to_character_offset (frame ._original_line , frame .end_colno )
472+ colno = _byte_offset_to_character_offset (
473+ frame_summary ._original_line , frame_summary .colno )
474+ end_colno = _byte_offset_to_character_offset (
475+ frame_summary ._original_line , frame_summary .end_colno )
472476
473477 anchors = None
474- if frame .lineno == frame .end_lineno :
478+ if frame_summary .lineno == frame_summary .end_lineno :
475479 with suppress (Exception ):
476480 anchors = _extract_caret_anchors_from_line_segment (
477- frame ._original_line [colno - 1 :end_colno - 1 ]
481+ frame_summary ._original_line [colno - 1 :end_colno - 1 ]
478482 )
479483 else :
480- end_colno = stripped_characters + len (frame .line .strip ())
484+ end_colno = stripped_characters + len (frame_summary .line .strip ())
481485
482486 row .append (' ' )
483487 row .append (' ' * (colno - stripped_characters ))
@@ -491,8 +495,8 @@ def format_frame(self, frame):
491495
492496 row .append ('\n ' )
493497
494- if frame .locals :
495- for name , value in sorted (frame .locals .items ()):
498+ if frame_summary .locals :
499+ for name , value in sorted (frame_summary .locals .items ()):
496500 row .append (' {name} = {value}\n ' .format (name = name , value = value ))
497501
498502 return '' .join (row )
@@ -514,27 +518,27 @@ def format(self):
514518 last_line = None
515519 last_name = None
516520 count = 0
517- for frame in self :
518- formatted_frame = self .format_frame ( frame )
521+ for frame_summary in self :
522+ formatted_frame = self .format_frame_summary ( frame_summary )
519523 if formatted_frame is None :
520524 continue
521- if (last_file is None or last_file != frame .filename or
522- last_line is None or last_line != frame .lineno or
523- last_name is None or last_name != frame .name ):
525+ if (last_file is None or last_file != frame_summary .filename or
526+ last_line is None or last_line != frame_summary .lineno or
527+ last_name is None or last_name != frame_summary .name ):
524528 if count > _RECURSIVE_CUTOFF :
525529 count -= _RECURSIVE_CUTOFF
526530 result .append (
527531 f' [Previous line repeated { count } more '
528532 f'time{ "s" if count > 1 else "" } ]\n '
529533 )
530- last_file = frame .filename
531- last_line = frame .lineno
532- last_name = frame .name
534+ last_file = frame_summary .filename
535+ last_line = frame_summary .lineno
536+ last_name = frame_summary .name
533537 count = 0
534538 count += 1
535539 if count > _RECURSIVE_CUTOFF :
536540 continue
537- result .append (self . format_frame ( frame ) )
541+ result .append (formatted_frame )
538542
539543 if count > _RECURSIVE_CUTOFF :
540544 count -= _RECURSIVE_CUTOFF
0 commit comments