Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork34.1k
Comments
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
gaogaotiantian commentedNov 5, 2023
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
| # 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I was trying to comment the reason why we should not replacesys.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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
ok, rephrase it then. I think it's too terse and not clear what that last part is talking about.
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 it better now?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
issafe_path not guaranteed to exist? the test doessys.flags.safe_path.
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 derived this from the original author, but from the source code it seems likesys.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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
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 notgetattr(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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
| # If safe_path(-P) is notset, sys.path[0] would be the directory | |
| # If safe_path(-P) is notselected, sys.path[0] would be the directory |
Uh oh!
There was an error while loading.Please reload this page.
Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
Uh oh!
There was an error while loading.Please reload this page.
gaogaotiantian commentedNov 27, 2023
Friendly ping@iritkatriel , is there anything I should improve here? |
iritkatriel commentedNov 27, 2023
This is probably worth an entry in whatnew. |
gaogaotiantian commentedNov 27, 2023
Whatsnew entry is added, let me know if you want me to rephrase it! |
Uh oh!
There was an error while loading.Please reload this page.
Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
cwalther commentedNov 28, 2023
Thanks! |
…ython#111762)Co-authored-by: Christian Walther <cwalther@users.noreply.github.com>
…ython#111762)Co-authored-by: Christian Walther <cwalther@users.noreply.github.com>
Uh oh!
There was an error while loading.Please reload this page.
pdbconvertssys.path[0]to the script's dir - that should not happen if using safe_path.Co-authored-by: Christian Walthercwalther@users.noreply.github.com