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,8 +109,12 @@ class Path:
|
||||||
self._case_correct = _case_correct
|
self._case_correct = _case_correct
|
||||||
|
|
||||||
if isinstance(path, Path):
|
if isinstance(path, Path):
|
||||||
absolute_path = path.absolute_path
|
self._absolute_path = path.absolute_path
|
||||||
else:
|
return
|
||||||
|
|
||||||
|
if not isinstance(path, str):
|
||||||
|
raise TypeError(f'path must be {Path} or {str}, not {type(path)}.')
|
||||||
|
|
||||||
path = path.strip()
|
path = path.strip()
|
||||||
if re.match(r'^[A-Za-z]:$', path):
|
if re.match(r'^[A-Za-z]:$', path):
|
||||||
# Bare Windows drive letter.
|
# Bare Windows drive letter.
|
||||||
|
@ -118,7 +122,6 @@ class Path:
|
||||||
path = normalize_sep(path)
|
path = normalize_sep(path)
|
||||||
path = os.path.normpath(path)
|
path = os.path.normpath(path)
|
||||||
absolute_path = os.path.abspath(path)
|
absolute_path = os.path.abspath(path)
|
||||||
|
|
||||||
self._absolute_path = normalize_sep(absolute_path, self.sep)
|
self._absolute_path = normalize_sep(absolute_path, self.sep)
|
||||||
|
|
||||||
def __contains__(self, other):
|
def __contains__(self, other):
|
||||||
|
|
Loading…
Reference in a new issue