Raise typeerror if not Path or str, and dedent by early return.
This commit is contained in:
parent
3049a62bc0
commit
f1b88b49fe
1 changed files with 12 additions and 9 deletions
|
@ -109,16 +109,19 @@ class Path:
|
|||
self._case_correct = _case_correct
|
||||
|
||||
if isinstance(path, Path):
|
||||
absolute_path = path.absolute_path
|
||||
else:
|
||||
path = path.strip()
|
||||
if re.match(r'^[A-Za-z]:$', path):
|
||||
# Bare Windows drive letter.
|
||||
path += self.sep
|
||||
path = normalize_sep(path)
|
||||
path = os.path.normpath(path)
|
||||
absolute_path = os.path.abspath(path)
|
||||
self._absolute_path = path.absolute_path
|
||||
return
|
||||
|
||||
if not isinstance(path, str):
|
||||
raise TypeError(f'path must be {Path} or {str}, not {type(path)}.')
|
||||
|
||||
path = path.strip()
|
||||
if re.match(r'^[A-Za-z]:$', path):
|
||||
# Bare Windows drive letter.
|
||||
path += self.sep
|
||||
path = normalize_sep(path)
|
||||
path = os.path.normpath(path)
|
||||
absolute_path = os.path.abspath(path)
|
||||
self._absolute_path = normalize_sep(absolute_path, self.sep)
|
||||
|
||||
def __contains__(self, other):
|
||||
|
|
Loading…
Reference in a new issue