Manual fixes to Python file

To see if I like the rules
This commit is contained in:
Geoffrey Frogeye 2025-05-08 18:29:03 +02:00
parent 34b545890d
commit 8179433c41
10 changed files with 612 additions and 547 deletions

View file

@ -1,7 +1,6 @@
#!/usr/bin/env python3
import os
import sys
import sys # noqa: I001
import contextlib
import pathlib
# From https://github.com/python/cpython/blob/v3.7.0b5/Lib/site.py#L436
@ -11,7 +10,7 @@ def register_readline() -> None:
try:
import readline
import rlcompleter
import rlcompleter # noqa: F401
except ImportError:
return
@ -23,14 +22,13 @@ def register_readline() -> None:
else:
readline.parse_and_bind("tab: complete")
try:
# An OSError here could have many causes, but the most likely one
# is that there's no .inputrc file (or .editrc file in the case of
# Mac OS X + libedit) in the expected location. In that case, we
# want to ignore the exception.
cm = contextlib.suppress(OSError)
with cm:
readline.read_init_file()
except OSError:
# An OSError here could have many causes, but the most likely one
# is that there's no .inputrc file (or .editrc file in the case of
# Mac OS X + libedit) in the expected location. In that case, we
# want to ignore the exception.
pass
if readline.get_current_history_length() == 0:
# If no history was loaded, default to .python_history.
@ -38,14 +36,11 @@ def register_readline() -> None:
# each interpreter exit when readline was already configured
# through a PYTHONSTARTUP hook, see:
# http://bugs.python.org/issue5845#msg198636
history = os.path.join(
os.path.expanduser("~"), ".cache/python_history"
)
try:
history = pathlib.Path("~/.cache/python_history").expanduser()
cm = contextlib.suppress(OSError)
with cm:
readline.read_history_file(history)
except OSError:
pass
atexit.register(readline.write_history_file, history)
sys.__interactivehook__ = register_readline
sys.__interactivehook__ = register_readline # noqa: attr-defined