Skip to content

Commit 855aac3

Browse files
committed
Extract method for replacing sys_path, and isolate realpath usage there.
1 parent d1d85b9 commit 855aac3

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

‎Lib/pdb.py‎

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

184184
class _ScriptTarget(_ExecutableTarget):
185185
def __init__(self, target):
186+
self._target = target
186187
self._check(target)
187-
self._target = os.path.realpath(target)
188-
189-
# If PYTHONSAFEPATH (-P) is not set, sys.path[0] is the directory
190-
# of pdb, and we should replace it with the directory of the script
191-
if not sys.flags.safe_path:
192-
sys.path[0] = os.path.dirname(self._target)
188+
self._replace_sys_path(target)
193189

194190
@staticmethod
195191
def _check(target):
@@ -203,6 +199,13 @@ def _check(target):
203199
print(f'Error: {target} is a directory')
204200
sys.exit(1)
205201

202+
@staticmethod
203+
def _replace_sys_path(target):
204+
# If PYTHONSAFEPATH (-P) is not set, sys.path[0] is the directory
205+
# of pdb, so replace it with the directory of the script
206+
if not sys.flags.safe_path:
207+
sys.path[0] = os.path.dirname(os.path.realpath(target))
208+
206209
def __repr__(self):
207210
return self._target
208211

0 commit comments

Comments
 (0)