Skip to content

Commit

Permalink
Merge pull request #22 from xyngular/josho/fix_bool_val
Browse files Browse the repository at this point in the history
fix: implementing `__len__` made the bool-value not what one would ex…
  • Loading branch information
joshorr authored Sep 4, 2024
2 parents f1df685 + 755f8a5 commit 8c80abb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tests/test_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
4 changes: 4 additions & 0 deletions xurls/url.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ---------

Expand Down

0 comments on commit 8c80abb

Please sign in to comment.