From e478aca49779aa1a5ec3cc6374c04be1bc92ca45 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Thu, 1 Aug 2019 08:46:37 -0700 Subject: [PATCH] Improve Path.__contains__ check. --- voussoirkit/pathclass.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/voussoirkit/pathclass.py b/voussoirkit/pathclass.py index c230ab5..4d6f35b 100644 --- a/voussoirkit/pathclass.py +++ b/voussoirkit/pathclass.py @@ -33,9 +33,17 @@ class Path: self.absolute_path = path def __contains__(self, other): - if isinstance(other, Path): - other = other.normcase - return other.startswith(self.normcase) + if isinstance(other, str): + other_norm = os.path.normcase(other) + elif isinstance(other, Path): + other_norm = other.normcase + else: + raise TypeError(other) + + self_norm = self.normcase + if not self_norm.endswith(os.sep): + self_norm += os.sep + return other_norm.startswith(self_norm) def __eq__(self, other): if not hasattr(other, 'absolute_path'):