-
-
Notifications
You must be signed in to change notification settings - Fork 30.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh-125600: Only show stale code warning on source code display commands #125601
Changes from 2 commits
b83fe61
1219003
3fbac42
9e2949c
fc46da5
546ab72
91bbe2a
df9e11e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -493,6 +493,15 @@ def _cmdloop(self): | |
except KeyboardInterrupt: | ||
self.message('--KeyboardInterrupt--') | ||
|
||
def _update_file_mtime(self): | ||
"""update the file mtime table with the current frame's file""" | ||
try: | ||
filename = self.curframe.f_code.co_filename | ||
mtime = os.path.getmtime(filename) | ||
self._file_mtime_table.setdefault(filename, mtime) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need to overwrite a previous value if the file changed on disk? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If not, then let's avoid going to the disk when the dict already has a value. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because we separated the update and check. We do not generate warnings on every update. We want to avoid But yes, we should avoid updating it if not necessary. |
||
except Exception: | ||
return | ||
|
||
def _validate_file_mtime(self): | ||
"""Check if the source file of the current frame has been modified since | ||
the last time we saw it. If so, give a warning.""" | ||
|
@@ -505,7 +514,7 @@ def _validate_file_mtime(self): | |
mtime != self._file_mtime_table[filename]): | ||
self.message(f"*** WARNING: file '{filename}' was edited, " | ||
"running stale code until the program is rerun") | ||
self._file_mtime_table[filename] = mtime | ||
self._file_mtime_table[filename] = mtime | ||
|
||
# Called before loop, handles display expressions | ||
# Set up convenience variable containers | ||
|
@@ -835,7 +844,7 @@ def onecmd(self, line): | |
a breakpoint command list definition. | ||
""" | ||
if not self.commands_defining: | ||
self._validate_file_mtime() | ||
self._update_file_mtime() | ||
if line.startswith('_pdbcmd'): | ||
command, arg, line = self.parseline(line) | ||
if hasattr(self, command): | ||
|
@@ -979,6 +988,7 @@ def completedefault(self, text, line, begidx, endidx): | |
|
||
def _pdbcmd_print_frame_status(self, arg): | ||
self.print_stack_trace(0) | ||
self._validate_file_mtime() | ||
self._show_display() | ||
|
||
def _pdbcmd_silence_frame_status(self, arg): | ||
|
@@ -1860,6 +1870,7 @@ def do_list(self, arg): | |
self.message('[EOF]') | ||
except KeyboardInterrupt: | ||
pass | ||
self._validate_file_mtime() | ||
do_l = do_list | ||
|
||
def do_longlist(self, arg): | ||
|
@@ -1878,6 +1889,7 @@ def do_longlist(self, arg): | |
self.error(err) | ||
return | ||
self._print_lines(lines, lineno, breaklist, self.curframe) | ||
self._validate_file_mtime() | ||
do_ll = do_longlist | ||
|
||
def do_source(self, arg): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Only show stale code warning in :mod:`pdb` when we display source code. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function name seems wrong - it's not "updating" the mtime if it's already there. It only sets it if it's not there.
Also, the docstring of
_validate_file_mtime
is no longer correct - it's not "since last time we saw it".There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed it to
init
, do you think it's better? Also changed the docstring a bit.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe "save"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is "save" better than "init"? Because I think save is similar to update. In this specific case, we only care for the entries that are not intialized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
init sounds to me like you are initialising the actual file_mtime, rather than saving a copy of it. How about save_initial_file_mtime?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay that makes sense. I thought about it and I don't think we need to put it in the command path now. We used to do that because we want the error message on every command. Now we can do it once in setup for all the frames and leave
onecmd
alone.