Skip to content

Commit df4f55c

Browse files
committed
Fix some small bugs and some lint...
"completer" is set to None, not False, when we don't have a completere. This happens in Python 3.13 right now In Python 3.13 we need to convert a FrameLocalsProxy to a dictionary in order to call exec. Some type lint was also done.
1 parent bb315f1 commit df4f55c

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

trepan/interface.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22
#
3-
# Copyright (C) 2010, 2013, 2015, 2018, 2023 Rocky Bernstein
3+
# Copyright (C) 2010, 2013, 2015, 2018, 2023, 2025 Rocky Bernstein
44
# <rocky@gnu.org>
55
#
66
# This program is free software: you can redistribute it and/or modify
@@ -49,7 +49,7 @@ def confirm(self, prompt, default):
4949
it's okay. `prompt' is printed; user response is returned."""
5050
raise NotImplementedError(NotImplementedMessage)
5151

52-
def errmsg(self, str, prefix="** "):
52+
def errmsg(self, msg, prefix="** "):
5353
"""Common routine for reporting debugger error messages."""
5454
raise NotImplementedError(NotImplementedMessage)
5555

@@ -74,10 +74,10 @@ def msg_nocr(self, msg):
7474
self.output.write(msg)
7575
return
7676

77-
def read_command(self, prompt):
77+
def read_command(self, prompt: str):
7878
raise NotImplementedError(NotImplementedMessage)
7979

80-
def readline(self, prompt, add_to_history=True):
80+
def readline(self, prompt: str, add_to_history=True):
8181
raise NotImplementedError(NotImplementedMessage)
8282

8383
pass

trepan/interfaces/user.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,11 @@
5151
write_history_file,
5252
)
5353
except ImportError:
54-
def write_history_file(histfile: str):
54+
def write_history_file(_: str):
5555
return
56+
def parse_and_bind(_: str):
57+
raise RuntimeError(f"Called {__name__}() when it doesn't exist")
58+
read_history_file = set_completer = parse_and_bind
5659
have_complete = False
5760
else:
5861
have_complete = False
@@ -73,8 +76,8 @@ def __init__(self, inp=None, out=None, opts={}):
7376
self.histfile = None
7477

7578
if self.input.use_history():
76-
self.complete = self.user_opts["complete"] and have_complete
77-
if self.complete:
79+
self.complete = self.user_opts["complete"] if have_complete else None
80+
if self.complete is not None:
7881
parse_and_bind("tab: complete")
7982
set_completer(self.complete)
8083
pass
@@ -96,7 +99,8 @@ def __init__(self, inp=None, out=None, opts={}):
9699
return
97100

98101
def user_write_history_file(self):
99-
write_history_file(self.histfile)
102+
if self.histfile is not None:
103+
write_history_file(self.histfile)
100104

101105
def close(self):
102106
"""Closes both input and output"""
@@ -166,7 +170,7 @@ def read_command(self, prompt=""):
166170
# Do something with history?
167171
return line
168172

169-
def readline(self, prompt=""):
173+
def readline(self, prompt="", add_to_history=True):
170174
if not self.readline == "prompt_toolkit":
171175
self.output.flush()
172176
pass

trepan/processor/command/python.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22
#
3-
# Copyright (C) 2009-2010, 2013, 2015, 2017, 2020, 2023-2024
3+
# Copyright (C) 2009-2010, 2013, 2015, 2017, 2020, 2023-2025
44
# Rocky Bernstein
55
#
66
# This program is free software: you can redistribute it and/or modify
@@ -119,11 +119,11 @@ def run(self, args):
119119
finally:
120120
sys.excepthook = old_sys_excepthook
121121

122+
interface = proc.intf[-1]
122123
# restore completion and our history if we can do so.
123-
if hasattr(proc.intf[-1], "complete"):
124+
if hasattr(interface, "complete") and interface.complete is not None:
124125
try:
125126
from readline import parse_and_bind, set_completer
126-
127127
parse_and_bind("tab: complete")
128128
set_completer(proc.intf[-1].complete)
129129
except ImportError:
@@ -182,8 +182,11 @@ def runcode(obj, code_obj):
182182
caller should be prepared to deal with it.
183183
184184
"""
185+
# In 3.13 FrameProxy was introduced. Not sure
186+
my_locals = dict(obj.locals) if not isinstance(obj.locals, dict) else obj.locals
187+
my_globals = dict(obj.globals) if not isinstance(obj.globals, dict) else obj.globals
185188
try:
186-
exec(code_obj, obj.locals, obj.globals)
189+
exec(code_obj, my_locals, my_globals)
187190
except SystemExit:
188191
raise
189192
except Exception:

0 commit comments

Comments
 (0)