@@ -183,34 +183,28 @@ class _ExecutableTarget:
183183
184184class _ScriptTarget (_ExecutableTarget ):
185185 def __init__ (self , target ):
186- self ._target = self ._safe_realpath (target )
187-
188- if not os .path .exists (self ._target ):
189- print (f'Error: { target } does not exist' )
190- sys .exit (1 )
191- if os .path .isdir (self ._target ):
192- print (f'Error: { target } is a directory' )
193- sys .exit (1 )
186+ self ._check (target )
187+ self ._target = os .path .realpath (target )
194188
195189 # If PYTHONSAFEPATH (-P) is not set, sys.path[0] is the directory
196190 # of pdb, and we should replace it with the directory of the script
197191 if not sys .flags .safe_path :
198192 sys .path [0 ] = os .path .dirname (self ._target )
199193
200- def __repr__ (self ):
201- return self ._target
202-
203194 @staticmethod
204- def _safe_realpath ( path ):
195+ def _check ( target ):
205196 """
206- Return the canonical path (realpath) if it is accessible from the userspace.
207- Otherwise (for example, if the path is a symlink to an anonymous pipe),
208- return the original path.
209-
210- See GH-142315.
197+ Check that target is plausibly a script.
211198 """
212- realpath = os .path .realpath (path )
213- return realpath if os .path .exists (realpath ) else path
199+ if not os .path .exists (target ):
200+ print (f'Error: { target } does not exist' )
201+ sys .exit (1 )
202+ if os .path .isdir (target ):
203+ print (f'Error: { target } is a directory' )
204+ sys .exit (1 )
205+
206+ def __repr__ (self ):
207+ return self ._target
214208
215209 @property
216210 def filename (self ):
0 commit comments