From 63c77a4d76e07a89aa6a6415be900aa211953e08 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 20 Feb 2018 06:47:04 +0100 Subject: [PATCH] urlmatch: Fix equality with non-UrlPattern types --- qutebrowser/utils/urlmatch.py | 2 ++ tests/unit/utils/test_urlmatch.py | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/qutebrowser/utils/urlmatch.py b/qutebrowser/utils/urlmatch.py index d2f9c4fe6..6bded760b 100644 --- a/qutebrowser/utils/urlmatch.py +++ b/qutebrowser/utils/urlmatch.py @@ -104,6 +104,8 @@ class UrlPattern: return hash(self._to_tuple()) def __eq__(self, other): + if not isinstance(other, UrlPattern): + return NotImplemented # pylint: disable=protected-access return self._to_tuple() == other._to_tuple() diff --git a/tests/unit/utils/test_urlmatch.py b/tests/unit/utils/test_urlmatch.py index 83746dcca..bda8c6eb0 100644 --- a/tests/unit/utils/test_urlmatch.py +++ b/tests/unit/utils/test_urlmatch.py @@ -519,6 +519,10 @@ def test_equal(text1, text2, equal): assert (hash(pat1) == hash(pat2)) == equal +def test_equal_string(): + assert urlmatch.UrlPattern("") != '' + + def test_repr(): pat = urlmatch.UrlPattern('https://www.example.com/') expected = ("qutebrowser.utils.urlmatch.UrlPattern("