]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Extract method for replacing sys_path, and isolate realpath usage there.
authorJason R. Coombs <jaraco@jaraco.com>
Mon, 8 Dec 2025 07:42:39 +0000 (02:42 -0500)
committerJason R. Coombs <jaraco@jaraco.com>
Mon, 8 Dec 2025 07:42:39 +0000 (02:42 -0500)
Lib/pdb.py

index 007541ed0a46b3fcbda51b3f96648cfa3ea076f0..1c2b70f6bdf555b1b1e02069f03a4dc4881863d5 100644 (file)
@@ -183,13 +183,9 @@ class _ExecutableTarget:
 
 class _ScriptTarget(_ExecutableTarget):
     def __init__(self, target):
+        self._target = target
         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)
+        self._replace_sys_path(target)
 
     @staticmethod
     def _check(target):
@@ -203,6 +199,13 @@ class _ScriptTarget(_ExecutableTarget):
             print(f'Error: {target} is a directory')
             sys.exit(1)
 
+    @staticmethod
+    def _replace_sys_path(target):
+        # If PYTHONSAFEPATH (-P) is not set, sys.path[0] is the directory
+        # of pdb, so replace it with the directory of the script
+        if not sys.flags.safe_path:
+            sys.path[0] = os.path.dirname(os.path.realpath(target))
+
     def __repr__(self):
         return self._target