File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -184,7 +184,7 @@ class _ExecutableTarget:
184184class _ScriptTarget (_ExecutableTarget ):
185185 def __init__ (self , target ):
186186 self ._check (target )
187- self ._target = os . path . realpath (target )
187+ self ._target = self . _safe_realpath (target )
188188
189189 # If PYTHONSAFEPATH (-P) is not set, sys.path[0] is the directory
190190 # of pdb, and we should replace it with the directory of the script
@@ -203,6 +203,18 @@ def _check(target):
203203 print (f'Error: { target } is a directory' )
204204 sys .exit (1 )
205205
206+ @staticmethod
207+ def _safe_realpath (path ):
208+ """
209+ Return the canonical path (realpath) if it is accessible from the userspace.
210+ Otherwise (for example, if the path is a symlink to an anonymous pipe),
211+ return the original path.
212+
213+ See GH-142315.
214+ """
215+ realpath = os .path .realpath (path )
216+ return realpath if os .path .exists (realpath ) else path
217+
206218 def __repr__ (self ):
207219 return self ._target
208220
You can’t perform that action at this time.
0 commit comments