Skip to content

Commit 612b7f6

Browse files
committed
Use early returns to reduce indentation level
1 parent 3f9d1b8 commit 612b7f6

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

Lib/pathlib.py

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -189,27 +189,25 @@ def compile_pattern(self, pattern):
189189
def resolve(self, path, strict=False):
190190
s = str(path)
191191
if not s:
192-
return path._accessor.getcwd()
192+
s = path._accessor.getcwd()
193+
if _getfinalpathname is None:
194+
return None # Means fallback on absolute
195+
if strict:
196+
return self._ext_to_normal(_getfinalpathname(s))
197+
s = path = os.path.abspath(s)
193198
previous_s = None
194-
if _getfinalpathname is not None:
195-
if strict:
196-
return self._ext_to_normal(_getfinalpathname(s))
199+
tail_parts = [] # End of the path after the first one not found
200+
while True:
201+
try:
202+
s = self._ext_to_normal(_getfinalpathname(s))
203+
except FileNotFoundError:
204+
previous_s = s
205+
s, tail = os.path.split(s)
206+
tail_parts.append(tail)
207+
if previous_s == s: # Root reached, fallback to abspath()
208+
return path
197209
else:
198-
s = path = os.path.abspath(s)
199-
tail_parts = [] # End of the path after the first one not found
200-
while True:
201-
try:
202-
s = self._ext_to_normal(_getfinalpathname(s))
203-
except FileNotFoundError:
204-
previous_s = s
205-
s, tail = os.path.split(s)
206-
tail_parts.append(tail)
207-
if previous_s == s:
208-
return path
209-
else:
210-
return os.path.join(s, *reversed(tail_parts))
211-
# Means fallback on absolute
212-
return None
210+
return os.path.join(s, *reversed(tail_parts))
213211

214212
def _split_extended_path(self, s, ext_prefix=ext_namespace_prefix):
215213
prefix = ''

0 commit comments

Comments
 (0)