GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — gh-99367: Do not mangle sys.path[0] in pdb if safe_path is set by gaogaotiantian · Pull Request #111762 · python/cpython Conversation
|
|
cc: @cwalther |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| # 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.
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
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem 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.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem 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.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Is it better now?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| 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.
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.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem 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.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem 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.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| # 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.
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 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Co-authored-by: Irit Katriel <[email protected]>
There was an error while loading. Please reload this page.
|
Friendly ping @iritkatriel , is there anything I should improve here? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
This is probably worth an entry in whatnew. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Whatsnew entry is added, let me know if you want me to rephrase it! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Co-authored-by: Irit Katriel <[email protected]>
|
Thanks! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…ython#111762) Co-authored-by: Christian Walther <[email protected]>
…ython#111762) Co-authored-by: Christian Walther <[email protected]>
The prelude restores the working directory as the first import root after the generated script moved to /tmp. Its `else` branch inserted that directory even when Python had deliberately left it out, defeating `-P` and `PYTHONSAFEPATH=1`, whose whole purpose is to keep a writable directory off the import path. Insert only when Python itself would have added a script directory. This matches how CPython fixed `pdb` in python/cpython#111762 and how `ipykernel` and `pyright` resolved the same problem. `sys.flags.safe_path` exists only on Python 3.11+, and this package supports 3.10, so it is read through `getattr` with a `False` default; 3.10 has no safe path mode, so the historical behaviour is preserved there. Verified on Python 3.12 and 3.10: - normal mode resolves the working directory, with existing PYTHONPATH entries behind it - `-P` and `PYTHONSAFEPATH=1` no longer import from the working directory - under safe path an existing PYTHONPATH entry still resolves, which is what Python does on its own - Python 3.10 raises no AttributeError and keeps the normal-mode behaviour Signed-off-by: danish9039 <[email protected]>
The prelude restores the working directory as the first import root after the generated script moved to /tmp. Its `else` branch inserted that directory even when Python had deliberately left it out, defeating `-P` and `PYTHONSAFEPATH=1`, whose whole purpose is to keep a writable directory off the import path. Insert only when Python itself would have added a script directory. This matches how CPython fixed `pdb` in python/cpython#111762 and how `ipykernel` and `pyright` resolved the same problem. `sys.flags.safe_path` exists only on Python 3.11+, and this package supports 3.10, so it is read through `getattr` with a `False` default; 3.10 has no safe path mode, so the historical behaviour is preserved there. Verified on Python 3.12 and 3.10: - normal mode resolves the working directory, with existing PYTHONPATH entries behind it - `-P` and `PYTHONSAFEPATH=1` no longer import from the working directory - under safe path an existing PYTHONPATH entry still resolves, which is what Python does on its own - Python 3.10 raises no AttributeError and keeps the normal-mode behaviour Signed-off-by: danish9039 <[email protected]>
The prelude restores the working directory as the first import root after the generated script moved to /tmp. Its `else` branch inserted that directory even when Python had deliberately left it out, defeating `-P` and `PYTHONSAFEPATH=1`, whose whole purpose is to keep a writable directory off the import path. Insert only when Python itself would have added a script directory. This matches how CPython fixed `pdb` in python/cpython#111762 and how `ipykernel` and `pyright` resolved the same problem. `sys.flags.safe_path` exists only on Python 3.11+, and this package supports 3.10, so it is read through `getattr` with a `False` default; 3.10 has no safe path mode, so the historical behaviour is preserved there. Verified on Python 3.12 and 3.10: - normal mode resolves the working directory, with existing PYTHONPATH entries behind it - `-P` and `PYTHONSAFEPATH=1` no longer import from the working directory - under safe path an existing PYTHONPATH entry still resolves, which is what Python does on its own - Python 3.10 raises no AttributeError and keeps the normal-mode behaviour Signed-off-by: danish9039 <[email protected]>
The prelude restores the working directory as the first import root after the generated script moved to /tmp. Its `else` branch inserted that directory even when Python had deliberately left it out, defeating `-P` and `PYTHONSAFEPATH=1`, whose whole purpose is to keep a writable directory off the import path. Insert only when Python itself would have added a script directory. This matches how CPython fixed `pdb` in python/cpython#111762 and how `ipykernel` and `pyright` resolved the same problem. `sys.flags.safe_path` exists only on Python 3.11+, and this package supports 3.10, so it is read through `getattr` with a `False` default; 3.10 has no safe path mode, so the historical behaviour is preserved there. Verified on Python 3.12 and 3.10: - normal mode resolves the working directory, with existing PYTHONPATH entries behind it - `-P` and `PYTHONSAFEPATH=1` no longer import from the working directory - under safe path an existing PYTHONPATH entry still resolves, which is what Python does on its own - Python 3.10 raises no AttributeError and keeps the normal-mode behaviour Signed-off-by: danish9039 <[email protected]>
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.