Skip to content

Commit 682069d

Browse files
committed
Pick target depending on preconditions
1 parent 572c780 commit 682069d

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

Lib/pdb.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,13 +183,16 @@ class _ExecutableTarget:
183183

184184
class _ScriptTarget(_ExecutableTarget):
185185
def __init__(self, target):
186+
self._orig_target = target
186187
self._target = os.path.realpath(target)
187188

188-
if not os.path.exists(self._target):
189-
print(f'Error: {target} does not exist')
189+
# Pass the original target to system functions
190+
# to support pseudofilesystems (GH-142315).
191+
if not os.path.exists(self._orig_target):
192+
print(f'Error: {self._orig_target} does not exist')
190193
sys.exit(1)
191-
if os.path.isdir(self._target):
192-
print(f'Error: {target} is a directory')
194+
if os.path.isdir(self._orig_target):
195+
print(f'Error: {self._orig_target} is a directory')
193196
sys.exit(1)
194197

195198
# If safe_path(-P) is not set, sys.path[0] is the directory
@@ -207,7 +210,8 @@ def filename(self):
207210
@property
208211
def code(self):
209212
# Open the file each time because the file may be modified
210-
with io.open_code(self._target) as fp:
213+
use_realpath = os.path.exists(self._target)
214+
with io.open_code(self._target if use_realpath else self._orig_target) as fp:
211215
return f"exec(compile({fp.read()!r}, {self._target!r}, 'exec'))"
212216

213217
@property
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Pdb can run scripts from pseudofiles. Patch by Bartosz Sławecki.

0 commit comments

Comments
 (0)