]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Extract a function to check the target. Remove the _safe_realpath, now no longer...
authorJason R. Coombs <jaraco@jaraco.com>
Mon, 8 Dec 2025 07:33:33 +0000 (02:33 -0500)
committerJason R. Coombs <jaraco@jaraco.com>
Mon, 8 Dec 2025 07:33:33 +0000 (02:33 -0500)
Lib/pdb.py

index 33ac6a13640f1f58e4383fac561e3f7fcc6eff1c..007541ed0a46b3fcbda51b3f96648cfa3ea076f0 100644 (file)
@@ -183,34 +183,28 @@ class _ExecutableTarget:
 
 class _ScriptTarget(_ExecutableTarget):
     def __init__(self, target):
-        self._target = self._safe_realpath(target)
-
-        if not os.path.exists(self._target):
-            print(f'Error: {target} does not exist')
-            sys.exit(1)
-        if os.path.isdir(self._target):
-            print(f'Error: {target} is a directory')
-            sys.exit(1)
+        self._check(target)
+        self._target = os.path.realpath(target)
 
         # If PYTHONSAFEPATH (-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:
             sys.path[0] = os.path.dirname(self._target)
 
-    def __repr__(self):
-        return self._target
-
     @staticmethod
-    def _safe_realpath(path):
+    def _check(target):
         """
-        Return the canonical path (realpath) if it is accessible from the userspace.
-        Otherwise (for example, if the path is a symlink to an anonymous pipe),
-        return the original path.
-
-        See GH-142315.
+        Check that target is plausibly a script.
         """
-        realpath = os.path.realpath(path)
-        return realpath if os.path.exists(realpath) else path
+        if not os.path.exists(target):
+            print(f'Error: {target} does not exist')
+            sys.exit(1)
+        if os.path.isdir(target):
+            print(f'Error: {target} is a directory')
+            sys.exit(1)
+
+    def __repr__(self):
+        return self._target
 
     @property
     def filename(self):