gh-99367: Do not mangle sys.path[0] in pdb if safe_path is set#111762
gh-99367: Do not mangle sys.path[0] in pdb if safe_path is set#111762iritkatriel merged 7 commits intopython:mainfrom
Conversation
|
cc: @cwalther |
Lib/pdb.py
Outdated
| # Replace pdb's dir with script's dir in front of module search path. | ||
| sys.path[0] = os.path.dirname(self) | ||
| # Replace pdb's dir with script's dir in front of module search path | ||
| # if safe_path is not set, otherwise sys.path[0] is not pdb's dir |
There was a problem hiding this comment.
| # if safe_path is not set, otherwise sys.path[0] is not pdb's dir | |
| # if safe_path is not set |
the part I removed seems a bit grammatically incorrect (and not really necessary) unless I'm missing something
There was a problem hiding this comment.
I was trying to comment the reason why we should not replace sys.path[0] - it was not obvious to me. We can either delete the comment or I can try to rephrase the whole thing to make more sense.
There was a problem hiding this comment.
ok, rephrase it then. I think it's too terse and not clear what that last part is talking about.
Lib/pdb.py
Outdated
| sys.path[0] = os.path.dirname(self) | ||
| # Replace pdb's dir with script's dir in front of module search path | ||
| # if safe_path is not set, otherwise sys.path[0] is not pdb's dir | ||
| if not getattr(sys.flags, 'safe_path', None): |
There was a problem hiding this comment.
is safe_path not guaranteed to exist? the test does sys.flags.safe_path.
There was a problem hiding this comment.
I derived this from the original author, but from the source code it seems like sys.flags.safe_path should always exist after 3.11. I'll change it here, maybe together with the comment after we decide what to do.
There was a problem hiding this comment.
I don’t remember exactly, but I probably added the check because I was not sure whether it’s okay to depend on ≥ 3.11. If you know that it is, go ahead and remove it.
Lib/pdb.py
Outdated
| # Replace pdb's dir with script's dir in front of module search path | ||
| # if safe_path is not set, otherwise sys.path[0] is not pdb's dir | ||
| if not getattr(sys.flags, 'safe_path', None): | ||
| # If safe_path(-P) is not set, sys.path[0] would be the directory |
There was a problem hiding this comment.
| # If safe_path(-P) is not set, sys.path[0] would be the directory | |
| # If safe_path (-P) is not selected, sys.path[0] would be the directory |
Co-authored-by: Irit Katriel <[email protected]>
|
Friendly ping @iritkatriel , is there anything I should improve here? |
|
This is probably worth an entry in whatnew. |
|
Whatsnew entry is added, let me know if you want me to rephrase it! |
Co-authored-by: Irit Katriel <[email protected]>
|
Thanks! |
…ython#111762) Co-authored-by: Christian Walther <[email protected]>
…ython#111762) Co-authored-by: Christian Walther <[email protected]>
pdbconvertssys.path[0]to the script's dir - that should not happen if using safe_path.Co-authored-by: Christian Walther [email protected]