On Sunday, December 5, 2021 at 9:56:03 AM UTC-6 Edward K. Ream wrote:

>  I have begun my study. I'll ask questions as needed. 

I like to ask questions of the code :-)  The split_root function defines 
"body" as follows:

def body(a, b, tag):
    return ''.join(lines[a-1:b and (b-1)])

The split_class function defines "body" this way:

def body(a, b, tag):
    return ''.join(nlines[a-1:b and (b-1)])

Notice: "b and (b-1)" may evaluate to None. But lines[a:None] means 
lines[a:]. I didn't know that None was a valid index!

For study purposes, I add traces to each:

def body(a, b, tag):  # split_root.
    lines2 = lines[a-1:b and (b-1)]
    g.trace(f" split_root: lines: {len(lines2):<4} {a!r:>4}:{b and 
(b-1)!r:<4} {tag}")
    return ''.join(lines2)

def body(a, b, tag):  # split_class
    lines2 = nlines[a-1:b and (b-1)]
    g.trace(f"split_class: lines: {len(lines2):<4} {a!r:>4}:{b and 
(b-1)!r:<4} {tag}")
    return ''.join(lines2)

Each call to these functions has a different tag (not shown).

These traces produce the following when importing difflib.py:

body  split_root: lines: 0       1:0    head: Imported Files...
body  split_root: lines: 0    2097:None tail: Imported Files...
body  split_root: lines: 38      1:38   Declarations
body  split_root: lines: 5      39:43   _calculate_ratio
body  split_root: lines: 654    44:697  class SequenceMatcher
body split_class: lines: 107     1:107  class SequenceMatcher::Declarations
body split_class: lines: 64    108:171  class SequenceMatcher::__init__
body split_class: lines: 12    172:183  class SequenceMatcher::set_seqs
body split_class: lines: 26    184:209  class SequenceMatcher::set_seq1
body split_class: lines: 44    210:253  class SequenceMatcher::set_seq2
body split_class: lines: 39    254:292  class SequenceMatcher::__chain_b
body split_class: lines: 116   293:408  class 
SequenceMatcher::find_longest_match
body split_class: lines: 71    409:479  class 
SequenceMatcher::get_matching_blocks
body split_class: lines: 55    480:534  class SequenceMatcher::get_opcodes
body split_class: lines: 50    535:584  class 
SequenceMatcher::get_grouped_opcodes
body split_class: lines: 25    585:609  class SequenceMatcher::ratio
body split_class: lines: 29    610:638  class SequenceMatcher::quick_ratio
body split_class: lines: 12    639:650  class 
SequenceMatcher::real_quick_ratio
body  split_root: lines: 49    698:746  get_close_matches
body  split_root: lines: 9     747:755  _keep_original_ws
body  split_root: lines: 327   756:1082 class Differ
body  split_root: lines: 2    1083:1084 Declarations
body  split_root: lines: 16   1085:1100 IS_LINE_JUNK
body  split_root: lines: 23   1101:1123 IS_CHARACTER_JUNK
body  split_root: lines: 11   1124:1134 _format_range_unified
body  split_root: lines: 73   1135:1207 unified_diff
body  split_root: lines: 12   1208:1219 _format_range_context
body  split_root: lines: 76   1220:1295 context_diff
body  split_root: lines: 17   1296:1312 _check_types
body  split_root: lines: 30   1313:1342 diff_bytes
body  split_root: lines: 37   1343:1379 ndiff
body  split_root: lines: 270  1380:1649 _mdiff
body  split_root: lines: 56   1650:1705 Declarations
body  split_root: lines: 351  1706:2056 class HtmlDiff(object)
body split_class: lines: 21      1:21   class HtmlDiff(object)::Declarations
body split_class: lines: 17     22:38   class HtmlDiff(object)::__init__
body split_class: lines: 27     39:65   class HtmlDiff(object)::make_file
body split_class: lines: 23     66:88   class 
HtmlDiff(object)::_tab_newline_replace
body split_class: lines: 55     89:143  class HtmlDiff(object)::_split_line
body split_class: lines: 28    144:171  class 
HtmlDiff(object)::_line_wrapper
body split_class: lines: 21    172:192  class 
HtmlDiff(object)::_collect_lines
body split_class: lines: 23    193:215  class HtmlDiff(object)::_format_line
body split_class: lines: 11    216:226  class HtmlDiff(object)::_make_prefix
body split_class: lines: 47    227:273  class 
HtmlDiff(object)::_convert_flags
body split_class: lines: 77    274:350  class HtmlDiff(object)::make_table
body  split_root: lines: 2    2057:2058 Declarations
body  split_root: lines: 32   2059:2090 restore
body  split_root: lines: 6    2091:2096 _test

This "picture" shows what is happening.  Pay particular attention to the 
ranges of line numbers.

The `class HtmlDiff` node contains 351 lines, which split_class then 
"allocates" to child nodes.  The picture shows that the child nodes "cover" 
the original lines.

Edward

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/leo-editor/bfd0005c-a0da-45a0-be99-1ceb673699can%40googlegroups.com.

Reply via email to