-
-
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
gh-99367: Do not mangle sys.path[0] in pdb if safe_path is set #111762
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.
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 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.
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.
is safe_path
not guaranteed to exist? the test does sys.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 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.
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 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.
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 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 <1055913+iritkatriel@users.noreply.github.com>
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 <1055913+iritkatriel@users.noreply.github.com>
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>
pdb
convertssys.path[0]
to the script's dir - that should not happen if using safe_path.Co-authored-by: Christian Walther cwalther@users.noreply.github.com