Skip to content

Commit

Permalink
Merge branch 'pdb'
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenfreund committed Mar 11, 2024
2 parents 338649f + d42a4f7 commit e9f066f
Showing 1 changed file with 32 additions and 15 deletions.
47 changes: 32 additions & 15 deletions src/chatdbg/chatdbg_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,11 @@ def _hide_lib_frames(self):
self.curframe_locals = self.curframe.f_locals

# Assume assertions are correct and the code leading to them is not!
current_line = linecache.getline(self.curframe.f_code.co_filename, self.lineno)
if current_line.strip().startswith('assert'):
self._error_specific_prompt += f"The code `{current_line.strip()}` is correct and MUST remain unchanged in your fix.\n"
if self.curframe.f_lineno != None:
current_line = linecache.getline(self.curframe.f_code.co_filename,
self.curframe.f_lineno)
if current_line.strip().startswith('assert'):
self._error_specific_prompt += f"The code `{current_line.strip()}` is correct and MUST remain unchanged in your fix.\n"

def execRcLines(self):

Expand Down Expand Up @@ -286,23 +288,36 @@ def do_info(self, arg):
Print the pydoc string (and source code, if available) for a name.
"""
try:
obj = self._getval(arg)
# try both given and unqualified form incase LLM biffs
args_to_try = [ arg, arg.split('.')[-1] ]
obj = None
for x in args_to_try:
try:
obj = eval(x, self.curframe.f_globals, self.curframe_locals)
break # found something so we're good
except:
# fail silently, try the next name
pass

# didn't find anything
if obj == None:
self.message(f"No name `{arg}` is visible in the current frame.")
return

if self._is_user_file(inspect.getfile(obj)):
self.do_source(arg)
self.do_source(x)
else:
self.do_pydoc(arg)
self.message(
f"You MUST assume that `{arg}` is specified and implemented correctly."
)
except NameError:
# message already printed in _getval
pass
self.do_pydoc(x)
self.message(f"You MUST assume that `{x}` is specified and implemented correctly.")
except OSError:
raise
except NameError:
# alread handled
pass
except Exception:
self.do_pydoc(arg)
self.do_pydoc(x)
self.message(
f"You MUST assume that `{arg}` is specified and implemented correctly."
f"You MUST assume that `{x}` is specified and implemented correctly."
)

def do_slice(self, arg):
Expand All @@ -316,6 +331,7 @@ def do_slice(self, arg):

index = self.curindex
_x = None
cell = None
while index > 0:
# print(index)
pos, _ = singletons.flow().get_position(self.stack[index][0])
Expand All @@ -338,7 +354,8 @@ def do_slice(self, arg):
blacken=True,
format_type=None)).rstrip()
else:
result = f"*** No information avaiable for {arg}, only {cell.used_symbols}. Run the command `p {arg}` to see its value."
used_symbols = set() if cell == None else cell.used_symbols
result = f"*** No information avaiable for {arg}, only {used_symbols}. Run the command `p {arg}` to see its value."
except OSError:
raise
except Exception as e:
Expand Down

0 comments on commit e9f066f

Please sign in to comment.