Is anyone else seeing a crash in str.translate?

7 views
Skip to first unread message

Edward K. Ream

unread,
Jul 8, 2026, 5:12:30 PM (10 hours ago) Jul 8
to leo-editor
Thomas reports this crash in leoGlobals.py:

File "c:\Tom\git\leo-editor\leo\core\leoGlobals.py", line 3702, in is_binary_string
    return bool(s.translate(None, bytes(aList)))  # type:ignore
                ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^
TypeError: str.translate() takes exactly one argument (2 given)

Does anyone else see anything like this?

I'm suspicious: git blames says this line was last changed in 2021.

1c81015582 (Edward K. Ream 2021-07-28 10:10:37 -0500 3702)
return bool(s.translate(None, bytes(aList)))  # type:ignore

There is a long history of mypy not understanding this line, hence the suppression.

Edward

Jacob Peck

unread,
Jul 8, 2026, 5:42:22 PM (9 hours ago) Jul 8
to leo-e...@googlegroups.com, leo-editor
In my quick look, that’s a python2-ism.  The deletechars parameter to string.translate is no longer a thing in Python 3.  I’m sure the code still runs, and maybe even is doing what you expect it to, but I believe the second param to translate is deprecated in py3, which might by why mypy complains.

Relevant StackOverflow thread from 2014: https://stackoverflow.com/a/23794836

Jake

On Jul 8, 2026, at 5:12 PM, Edward K. Ream <edre...@gmail.com> wrote:


--
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 leo-editor+...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/leo-editor/6e29097d-5858-4134-9973-f4c92fb8bca4n%40googlegroups.com.

Edward K. Ream

unread,
Jul 8, 2026, 7:45:10 PM (7 hours ago) Jul 8
to leo-e...@googlegroups.com
On Wed, Jul 8, 2026 at 4:42 PM Jacob Peck wrote:
In my quick look, that’s a python2-ism.  The deletechars parameter to string.translate is no longer a thing in Python 3.  I’m sure the code still runs, and maybe even is doing what you expect it to, but I believe the second param to translate is deprecated in py3, which might by why mypy complains.

Here is the official 3.14 reference. I agree something is fishy, but I think the fishiness is a separate issue.

After an hour of futzing, the following Leonine script works as expected:

g.cls()
table = (
    'Test1',
    'Test2' + chr(7),
)
delete_s = ''.join(chr(i) for i in range(20) if not chr(i).isprintable())
print(repr(delete_s))
for s in table:
    trans_table = str.maketrans('', '', delete_s)
    print(repr(s), repr(s.translate(trans_table)))


The output is:

'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13'
'Test1' 'Test1'
'Test2\x07' 'Test2'

Oops. The delete string deletes too many characters, but it's getting close.

I'll create a PR based on this idea. For now, though, I think this issue is not the cause of Thomas's woes.

Edward

Thomas Passin

unread,
Jul 8, 2026, 7:52:39 PM (7 hours ago) Jul 8
to leo-editor
I tried opening the same outlines (and my workbook.leo seems to be the one that sees most of the errors) with Python 3.12, 3.13, and 3.14, all with the same results.

Edward K. Ream

unread,
Jul 8, 2026, 7:57:36 PM (7 hours ago) Jul 8
to leo-e...@googlegroups.com
On Wed, Jul 8, 2026 at 6:44 PM Edward K. Ream <edre...@gmail.com> wrote:

After an hour of futzing, the following Leonine script works as expected:

Here is another try:

g.cls()
table = (
    'Test1',
    'Test2' + chr(7),  # Printable ??
    'Test3\n',
    'Test4' + chr(1),
)
non_binary = [7, 8, 9, 10, 12, 13, 27] + list(range(0x20, 0x100))
delete_s = ''.join(chr(i) for i in range(255) if i not in non_binary)

trans_table = str.maketrans('', '', delete_s)
print(repr(delete_s))
for s in table:
    print(repr(s), repr(s.translate(trans_table)))

And here is the output.

'\x00\x01\x02\x03\x04\x05\x06\x0b\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1c\x1d\x1e\x1f'
'Test1' 'Test1'
'Test2\x07' 'Test2\x07'
'Test3\n' 'Test3\n'
'Test4\x01' 'Test4'

I think this is getting closer.

Edward

Jacob Peck

unread,
Jul 8, 2026, 8:11:35 PM (7 hours ago) Jul 8
to leo-e...@googlegroups.com
I was able to trigger the same str.translate bug on my Win10/Python3.10 environment.  I git bisected to the offending commit, and added notes on the bug on Github.

--
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 leo-editor+...@googlegroups.com.

Thomas Passin

unread,
Jul 8, 2026, 11:44:23 PM (3 hours ago) Jul 8
to leo-editor
In Linux, I am not seeing the s.translate() error. But the issue I reported elsewhere is there on Linux too - cannot open files in the Recent Files list. 

I also get a new error on Linux. I have mapped CTRL+= and CTRL+- to commands, but they don't work and report this error:

doPlainChar Not plain: <KeyStroke: 'Ctrl+='> eventFilter,masterKeyHandler,insertCharFromEvent,selfInsertCommand

Thomas Passin

unread,
Jul 8, 2026, 11:46:30 PM (3 hours ago) Jul 8
to leo-editor
On Wednesday, July 8, 2026 at 11:44:23 PM UTC-4 Thomas Passin wrote:
In Linux, I am not seeing the s.translate() error. But the issue I reported elsewhere is there on Linux too - cannot open files in the Recent Files list. 

The error message was 

  File "/home/tom/git/leo-editor/leo/plugins/qt_frame.py", line 2759, in qt_add_command_callback
    return command()
TypeError: RecentFilesManager.createRecentFilesMenuItems.<locals>.recentFilesCallback() missing 1 required positional argument: 'event'


 

Thomas Passin

unread,
12:12 AM (3 hours ago) 12:12 AM
to leo-editor
The problems on Linux are going to be  tricky. The CTR-key issue happens on one distro but not another.  I think the difference is whether X11 or Wayland is used as the window manager - my VM that uses (I think) X11 recognizes the key combo while the Wayland one (again, I *think*) does not.

In addition, in the second VM, Linux Mint, based on Ubuntu, has an entirely new problem - when I load one particular outline (not my workbook) I get the following traceback, and although the outline loads there is no menu bar:

Unexpected exception reading '/home/tom/Leo-projects/zettel-browser/zettel2.leo'
Traceback (most recent call last):

  File "/home/tom/git/leo-editor/leo/core/leoApp.py", line 2399, in doPostPluginsInit
    c = g.openWithFileName(fn, gui=g.app.gui, old_c=None)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/tom/git/leo-editor/leo/core/leoGlobals.py", line 3748, in openWithFileName
    return g.app.loadManager.openWithFileName(fileName, gui, old_c)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/tom/git/leo-editor/leo/core/leoApp.py", line 3182, in openWithFileName
    return lm.openExistingLeoFile(file_name, gui, old_c)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/tom/git/leo-editor/leo/core/leoApp.py", line 3391, in openExistingLeoFile
    v = c.fileCommands.getAnyLeoFileByName(fn, readAtFileNodesFlag=bool(previousSettings))
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/tom/git/leo-editor/leo/core/leoFileCommands.py", line 960, in getAnyLeoFileByName
    v = fc._getLeoFileByName(path, readAtFileNodesFlag)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/tom/git/leo-editor/leo/core/leoFileCommands.py", line 1051, in _getLeoFileByName
    recoveryNode = fc.readExternalFiles()
                   ^^^^^^^^^^^^^^^^^^^^^^

  File "/home/tom/git/leo-editor/leo/core/leoFileCommands.py", line 1081, in readExternalFiles
    fc.setPositionsFromVnodes()

  File "/home/tom/git/leo-editor/leo/core/leoFileCommands.py", line 1401, in setPositionsFromVnodes
    current = self.archivedPositionToPosition(str_pos)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/tom/git/leo-editor/leo/core/leoFileCommands.py", line 1239, in archivedPositionToPosition
    return self.c.archivedPositionToPosition(s)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/tom/git/leo-editor/leo/core/leoCommands.py", line 3689, in archivedPositionToPosition
    if p.hasNext():
       ^^^^^^^^^^^

  File "/home/tom/git/leo-editor/leo/core/leoNodes.py", line 924, in hasNext
    parent_v = p._parentVnode()  # PR #4767 # May throw ValueError
               ^^^^^^^^^^^^^^^^

  File "/home/tom/git/leo-editor/leo/core/leoNodes.py", line 1388, in _parentVnode
    raise ValueError(f"{tag} Empty p: {p!r} callers: {g.callers()}")

ValueError: p._parentVnode Empty p: <pos 140055864398400 [2] None> callers: setPositionsFromVnodes,archivedPositionToPosition,archivedPositionToPosition,hasNext


Note that this outline has a few nodes that have neither headlines nor body text (I'm using them as visual spacers). It loads normally on Windows, and apparently so on the other Linux VM.
Reply all
Reply to author
Forward
0 new messages