Antoine Pitrou avatar Antoine Pitrou committed 03e9dfb

(fix #11) Comparisons with non-Path objects don't fail with AttributeError anymore

Comments (0)

Files changed (2)

             return self._cached_cparts
 
     def __eq__(self, other):
+        if not isinstance(other, PurePath):
+            return NotImplemented
         return self._cparts == other._cparts and self._flavour is other._flavour
 
     def __ne__(self, other):
             return self._hash
 
     def __lt__(self, other):
-        if self._flavour is not other._flavour:
+        if not isinstance(other, PurePath) or self._flavour is not other._flavour:
             return NotImplemented
         return self._cparts < other._cparts
 
     def __le__(self, other):
-        if self._flavour is not other._flavour:
+        if not isinstance(other, PurePath) or self._flavour is not other._flavour:
             return NotImplemented
         return self._cparts <= other._cparts
 
     def __gt__(self, other):
-        if self._flavour is not other._flavour:
+        if not isinstance(other, PurePath) or self._flavour is not other._flavour:
             return NotImplemented
         return self._cparts > other._cparts
 
     def __ge__(self, other):
-        if self._flavour is not other._flavour:
+        if not isinstance(other, PurePath) or self._flavour is not other._flavour:
             return NotImplemented
         return self._cparts >= other._cparts
 
         self.assertNotEqual(P('a/b'), P())
         self.assertNotEqual(P('/a/b'), P('/'))
         self.assertNotEqual(P(), P('/'))
+        self.assertNotEqual(P(), "")
+        self.assertNotEqual(P(), {})
+        self.assertNotEqual(P(), int)
 
     def test_match_common(self):
         P = self.cls
         assertLess(a, d)
         assertLess(b, c)
         assertLess(c, d)
+        if sys.version_info > (3,):
+            with self.assertRaises(TypeError):
+                P() < {}
+        else:
+            P() < {}
 
     def test_parts_common(self):
         sep = self.sep
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.