Is anyone else seeing a crash in str.translate?

2 views
Skip to first unread message

Edward K. Ream

unread,
5:12 PM (4 hours ago) 5:12 PM
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,
5:42 PM (3 hours ago) 5:42 PM
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,
7:45 PM (1 hour ago) 7:45 PM
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,
7:52 PM (1 hour ago) 7:52 PM
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,
7:57 PM (1 hour ago) 7:57 PM
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,
8:11 PM (1 hour ago) 8:11 PM
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.
Reply all
Reply to author
Forward
0 new messages