diff --git a/tests/test_url.py b/tests/test_url.py index f4c43d7..6fa1346 100644 --- a/tests/test_url.py +++ b/tests/test_url.py @@ -152,3 +152,8 @@ def test_url_dict_access_query_values(): assert url.query == {'a': '1'} +def test_url_bool_value(): + assert not Url() + assert Url('a') + assert Url(query={'day': 'today'}) + assert Url(host='example.com') diff --git a/xurls/url.py b/xurls/url.py index 25206e6..341322a 100644 --- a/xurls/url.py +++ b/xurls/url.py @@ -1186,6 +1186,10 @@ def __len__(self): def __delitem__(self, key): self.query_remove(key) + def __bool__(self): + # Check to see if `url` is empty in terms of any url string it would generate. + return bool(str(self)) + # --------------------------- # --------- Private ---------