From f1b88b49fe795383a8f6456f5b72557db73ed405 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Sun, 14 Nov 2021 22:18:03 -0800 Subject: [PATCH] Raise typeerror if not Path or str, and dedent by early return. --- voussoirkit/pathclass.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/voussoirkit/pathclass.py b/voussoirkit/pathclass.py index 604ce7c..67ab085 100644 --- a/voussoirkit/pathclass.py +++ b/voussoirkit/pathclass.py @@ -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):