-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
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
bpo-44554: refactor pdb targets (and internal tweaks) #26992
Conversation
|
||
if not run_as_module: | ||
mainpyfile = os.path.realpath(mainpyfile) |
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.
This line changes the meaning of mainpyfile
mid-function. It's because of this behavior that ScriptTarget contains an 'orig' property (to keep both representations), even though the "real path" form is the preferred one except during error checking.
This changes the behavior of pdb, right? |
This PR extracts the refactoring only, but not the fix for bpo-44461, as discussed in iritkatriel#16.
One place this refactoring could go awry is if there were other callers of Please do have a look at this approach as it focuses on the refactoring and ignores the concerns for now in fixing the reported issue. |
I do not believe this changes the behavior except for a couple subtle differences. I'll point those out in the diff. |
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.
A refactor changes the code to improve its structure without changing its behavior. I don't think you can call this a refactor.
When you're done making the requested changes, leave the comment: |
@@ -1674,28 +1706,19 @@ def main(): | |||
print(_usage) | |||
sys.exit(2) | |||
|
|||
commands = [] | |||
run_as_module = False | |||
for opt, optarg in opts: |
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.
Previously, the opts would be iterated over just once. In this new code, they are iterated over three times. Any performance degradation is negligible and outweighed by the value of disentangling the concerns.
|
||
target.check() | ||
|
||
sys.argv[:] = args # Hide "pdb.py" and pdb options from argument list |
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.
In the previous implementation, assignment of sys.argv[:]
would happen before the sys.path
change. In the new code, the sys.path
change happens during the ScriptTarget.check
. I contend these two operations are independent and can happen in any order.
This PR doesn't really have anything to do with the reported issue. It should be a new BPO. |
return res | ||
|
||
def check(self): | ||
if not os.path.exists(self): |
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.
Previously, the existence check was done on mainpyfile
before it was mutated to a "real path". Now the existence check is the real path. If compatibility is needed, this line could be changed to:
if not os.path.exists(self): | |
if not os.path.exists(self.orig): |
But in my opinion, the existence check on either form is equivalent, and the form presented is more readable and distracts less from the primary intention for self.orig
(the error message).
Perhaps I'm using the term too loosely. I believe the changes do not change the behavior or interfaces for the intended use-cases. |
Respectfully, I disagree. The whole point of this refactor is to enable an earlier check for a runpy module target, symmetric to the syntax check on a script target, a technique which has been shown to fix the issue (thanks to your analysis and test). |
I think you are using it too loosely. A refactor improves the code without changing its behavior. As I said, pdb has quite a few different use cases. I don't know it well enough to tell which changes are minor and which will break someone's debugger. Any behavior change needs to be associated with a bpo and news item that states clearly what the change is, not sneaked into a refactor. I'm also not sure about the motivation here. We have a fix for the reported bug. |
I've updated the blurb and PR title to reflect that it's more than a refactor. But I do genuinely expect this change to result in no significant behavior change. Can you point to a behavior change that you think is more than a refactor?
The motivation comes from my observation here that when the target is a script, there's a separate check for its existence (and similarly later a separate trap for bad syntax) that doesn't go through the Pdb interactive module. In my opinion, passing an invalid module to As I analyzed the issue, following your analysis and initial patch, I felt uneasy with adding the |
I believe that by first applying this refactor, then applying the test and fix in iritkatriel#16, you get a superior fix, avoiding adding a |
Since it handles bad modules differently (we agree on that right?) it's already more than a refactor. That may be a minor change, it might be a good change, I don't know. I need to spend some time reviewing it. I've moved on to work on something else between last week and now. I don't have time at the moment to convince myself that your change is safe. I'll have a look when I have time, unless someone else will before me. |
Sorry this wasn't clear. In this change, But as I think about it, perhaps the concerns this change addresses could be enumerated in its own bug.
No problem. I understand. Thanks for taking the time to review as much as you have already and for keeping me apprised of your schedule so I'm not left feeling abandoned. |
I have made the requested changes; please review again |
Thanks for making the requested changes! @iritkatriel: please review the changes made to this pull request. |
Misc/NEWS.d/next/Library/2021-07-02-18-17-56.bpo-44554.aBUmJo.rst
Outdated
Show resolved
Hide resolved
…n properties of the Target object.
In fe8aea5, I've pushed an additional refactor that consolidates This change has the additional benefit of restoring the association of the comments with their function. Prior to this change, the two block comments in |
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.
This version is indeed clearer. Can spec() and details() be _spec() and _details()?
…Union in the module.
Done in c91ba80. |
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.
LGTM
@jaraco: Status check is done, and it's a success ❌ . |
@jaraco: Status check is done, and it's a success ✅ . |
Sorry, I can't merge this PR. Reason: |
@jaraco: Status check is done, and it's a success ✅ . |
* origin/main: (1146 commits) bpo-42064: Finalise establishing sqlite3 global state (pythonGH-27155) bpo-44678: Separate error message for discontinuous padding in binascii.a2b_base64 strict mode (pythonGH-27249) correct spelling (pythonGH-27076) bpo-44524: Add missed __name__ and __qualname__ to typing module objects (python#27237) bpo-27513: email.utils.getaddresses() now handles Header objects (python#13797) Clean up comma usage in Doc/library/functions.rst (python#27083) bpo-42238: Fix small rst issue in NEWS.d/. (python#27238) bpo-41972: Tweak fastsearch.h string search algorithms (pythonGH-27091) bpo-44340: Add support for building with clang full/thin lto (pythonGH-27231) bpo-44661: Update property_descr_set to use vectorcall if possible. (pythonGH-27206) bpo-44645: Check for interrupts on any potentially backwards edge (pythonGH-27216) bpo-41546: make pprint (like print) not write to stdout when it is None (pythonGH-26810) bpo-44554: refactor pdb targets (and internal tweaks) (pythonGH-26992) bpo-43086: Add handling for out-of-spec data in a2b_base64 (pythonGH-24402) bpo-44561: Update hyperlinks in Doc/distributing/index.rst (python#27032) bpo-42355: symtable.get_namespace() now checks whether there are multiple or any namespaces found (pythonGH-23278) bpo-44654: Do not export the union type related symbols (pythonGH-27223) bpo-44633: Fix parameter substitution of the union type with wrong types. (pythonGH-27218) bpo-44654: Refactor and clean up the union type implementation (pythonGH-27196) bpo-20291: Fix MSVC warnings in getargs.c (pythonGH-27211) ...
https://bugs.python.org/issue44554
Automerge-Triggered-By: GH:jaraco