diff --git a/CHANGES/1401.misc.rst b/CHANGES/1401.misc.rst new file mode 100644 index 00000000..96670eb9 --- /dev/null +++ b/CHANGES/1401.misc.rst @@ -0,0 +1 @@ +Improved performance of passing a `dict` or `str` to :py:meth:`~yarl.URL.extend_query` -- by :user:`bdraco`. diff --git a/yarl/_query.py b/yarl/_query.py index 65420356..6a663fc9 100644 --- a/yarl/_query.py +++ b/yarl/_query.py @@ -97,10 +97,12 @@ def get_str_query(*args: Any, **kwargs: Any) -> Union[str, None]: return None if not query: return "" - if isinstance(query, Mapping): + if type(query) is dict: return get_str_query_from_sequence_iterable(query.items()) - if isinstance(query, str): + if type(query) is str or isinstance(query, str): return QUERY_QUOTER(query) + if isinstance(query, Mapping): + return get_str_query_from_sequence_iterable(query.items()) if isinstance(query, (bytes, bytearray, memoryview)): msg = "Invalid query type: bytes, bytearray and memoryview are forbidden" raise TypeError(msg)