No more big code changes to Leo

50 views
Skip to first unread message

Edward K. Ream

unread,
Apr 24, 2022, 4:16:49 PM4/24/22
to leo-editor
#2601 is likely to contain the last large change to Leo's code base. The corresponding PR #2604 changes 94 files! These changes will be part of 6.6.2.

#2601 explains why the risks involved in making so many changes were justified:

- The changes allow Leo to check almost all of Leo's source files.
- mypy found some real bugs.
- We will test the resulting code for about a month before releasing Leo 6.6.2.

I plan no further mass code changes. In particular, I won't do the following:

I won't fix hanging indented comments

For example:

zoom_dict: Dict[str, int] = {}
    # Keys are key::settings_names,
    # values are cumulative font size.

Yes, such comments violate PEP 8, but I often prefer them. I'm not going to risk changing them!

I won't improve comments

Heh. We can improve the above example:

# Dict[ key::settings_name, cumulative font size]
zoom_dict: Dict[str, int] = {}

But no, I'm not going to make such changes!

Summary

Perfectionism is not our friend. It's time to move on.

Edward

tbp1...@gmail.com

unread,
Apr 24, 2022, 9:14:33 PM4/24/22
to leo-editor
D'accord.  Save such things for new work.

Edward K. Ream

unread,
Apr 24, 2022, 9:22:11 PM4/24/22
to leo-editor
On Sun, Apr 24, 2022 at 8:14 PM tbp1...@gmail.com <tbp1...@gmail.com> wrote:
D'accord.  Save such things for new work.

And clear the mind for new projects :-)

Edward

Edward K. Ream

unread,
Apr 25, 2022, 10:00:08 AM4/25/22
to leo-editor
On Sunday, April 24, 2022 at 3:16:49 PM UTC-5 Edward K. Ream wrote:

I won't fix hanging indented comments

My subconscious complained doing the work by hand, but I have just completed the first draft of a script that removes hanging indents automatically. So I do plan to remove these hangnails for 6.6.2. This project will help clear my mind for what's next.

Edward

P.S. Here is the first draft of the heart of the script:

compound_statement = (
    # Leo doesn't use 'match'
    'async ', 'class ', 'def ', 'else:', 'elif ', 'except',
    'finally:', 'for ', 'if ', 'try:', 'while ', 'with ',
)
pat = re.compile(r'\)\s*->.*:\s*$')  # End of multiline def.

def convert(p: Any) -> None:
    """Convert all hanging comments in p.b."""
    changed, last_lws, last_s, result = False, '', '', []
    for s in p.b.split('\n'):
        s1 = last_s.lstrip()
        s2 = s.lstrip()
        n = len(s) - len(s2)
        lws = s[:n]
        if (
            s1 and s2.startswith('#')
            and not pat.match(s1)
            and not s1.startswith(('#', '"""', "'''"))
            and not s1.endswith(('[', '(', '{'))
            and not s1.startswith(compound_statement)
            and last_lws < lws
        ):
            changed = True
            if len(last_s) + len(s2) < 85:  # Emit one line.
                result.append(f"{last_s}  {s2}")
                g.printObj([last_s, s, f"{last_s}  {s2}\n"], tag=p.h)
            else:  # Emit two lines.
                result.append(f"{last_lws}{s2}")
                result.append(last_s)
                g.printObj([last_s, s, f"{last_lws}{s2}", last_s], tag=p.h)
        else:
            result.append(s)
        last_lws = lws
        last_s = s
    if changed:
        g.printObj('\n'.join(result), tag=f"RESULT: {p.h}")
        # p.b = '\n'.join(result)

The script is looking good on initial tests. The changed text will be part of Leo 6.6.2.

Edward

Edward K. Ream

unread,
Apr 25, 2022, 5:22:36 PM4/25/22
to leo-editor
On Monday, April 25, 2022 at 9:00:08 AM UTC-5 Edward K. Ream wrote:

P.S. Here is the first draft of the heart of the script:

There were some serious errors in the first draft. The first comment of PR #2622 contains the latest version, including the top-level `@button` code.

Edward

Edward K. Ream

unread,
Apr 25, 2022, 10:31:02 PM4/25/22
to leo-editor


On Monday, April 25, 2022 at 9:00:08 AM UTC-5 Edward K. Ream wrote:

> My subconscious complained doing the work by hand.

Not my subconscious, my inner critic. Anyway, I developed the script and removed hanging comments in less than 24 hours.  See PR #2622.  I'll merge this PR into devel after releasing 6.6.1.

When I see the results, I wonder why hanging indents were a good idea.

Edward

jkn

unread,
Apr 26, 2022, 6:26:58 AM4/26/22
to leo-editor
I'm pleased to see this change - those hanging indented comments always me
twitch a little  when I browsed the codebase. I wasn't going to make a noise
about it because ... hey, it's your code ... but FWIW I think this is useful work.

    J^n

Edward K. Ream

unread,
Apr 26, 2022, 7:17:37 AM4/26/22
to leo-editor
On Tuesday, April 26, 2022 at 5:26:58 AM UTC-5 jkn wrote:
I'm pleased to see this change - those hanging indented comments always me
twitch a little  when I browsed the codebase. I wasn't going to make a noise
about it because ... hey, it's your code ... but FWIW I think this is useful work.

Thanks. As I made the changes I became more and more dissatisfied with the hanging comments.

Edward
Reply all
Reply to author
Forward
0 new messages