From 70507701b780edd9aa5a7d8b1dc047dd56356766 Mon Sep 17 00:00:00 2001 From: johnslavik Date: Sun, 7 Dec 2025 14:26:18 +0100 Subject: [PATCH] Pick target depending on preconditions --- Lib/pdb.py | 10 ++++++---- .../2025-12-07-02-36-24.gh-issue-142315.02o5E_.rst | 1 + 2 files changed, 7 insertions(+), 4 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2025-12-07-02-36-24.gh-issue-142315.02o5E_.rst diff --git a/Lib/pdb.py b/Lib/pdb.py index 1506e3d47098..5729624ba139 100644 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -183,15 +183,17 @@ class _ExecutableTarget: class _ScriptTarget(_ExecutableTarget): def __init__(self, target): - self._target = os.path.realpath(target) - - if not os.path.exists(self._target): + if not os.path.exists(target): print(f'Error: {target} does not exist') sys.exit(1) - if os.path.isdir(self._target): + if os.path.isdir(target): print(f'Error: {target} is a directory') sys.exit(1) + # Be careful with realpath to support pseudofilesystems (GH-142315). + realpath = os.path.realpath(target) + self._target = realpath if os.path.exists(realpath) else target + # If safe_path(-P) is not set, sys.path[0] is the directory # of pdb, and we should replace it with the directory of the script if not sys.flags.safe_path: diff --git a/Misc/NEWS.d/next/Library/2025-12-07-02-36-24.gh-issue-142315.02o5E_.rst b/Misc/NEWS.d/next/Library/2025-12-07-02-36-24.gh-issue-142315.02o5E_.rst new file mode 100644 index 000000000000..b3941fdd5231 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-12-07-02-36-24.gh-issue-142315.02o5E_.rst @@ -0,0 +1 @@ +Pdb can run scripts from pseudofiles. Patch by Bartosz Sławecki. -- 2.47.3