diff --git a/tests/test_update_query.py b/tests/test_update_query.py index 36c1de379..d45299236 100644 --- a/tests/test_update_query.py +++ b/tests/test_update_query.py @@ -219,3 +219,12 @@ def test_update_query_multiple_keys(): u2 = url.update_query([("a", "3"), ("a", "4")]) assert str(u2) == "http://example.com/path?a=3&a=4" + + +# mod + +def test_update_query_with_mod_operator(): + url = URL("http://example.com/") + assert str(url % {"a": "1"}) == "http://example.com/?a=1" + assert str(url % {"a": "1"} % {"b": "2"}) == "http://example.com/?a=1&b=2" + assert str(url % {"a": "1"} % {"a": "3", "b": "2"}) == "http://example.com/?a=3&b=2" diff --git a/yarl/__init__.py b/yarl/__init__.py index 3ec3fadbf..a948a991e 100644 --- a/yarl/__init__.py +++ b/yarl/__init__.py @@ -307,6 +307,9 @@ def __truediv__(self, name): return URL( self._val._replace(path=new_path, query="", fragment=""), encoded=True ) + + def __mod__(self, query): + return self.update_query(query) def __bool__(self) -> bool: return bool(