Skip to content

Commit 71d171e

Browse files
authored
Add a fast path to get_str_query for dict and str (#1401)
1 parent 8ce8d67 commit 71d171e

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

CHANGES/1401.misc.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Improved performance of passing a `dict` or `str` to :py:meth:`~yarl.URL.extend_query` -- by :user:`bdraco`.

yarl/_query.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,12 @@ def get_str_query(*args: Any, **kwargs: Any) -> Union[str, None]:
9797
return None
9898
if not query:
9999
return ""
100-
if isinstance(query, Mapping):
100+
if type(query) is dict:
101101
return get_str_query_from_sequence_iterable(query.items())
102-
if isinstance(query, str):
102+
if type(query) is str or isinstance(query, str):
103103
return QUERY_QUOTER(query)
104+
if isinstance(query, Mapping):
105+
return get_str_query_from_sequence_iterable(query.items())
104106
if isinstance(query, (bytes, bytearray, memoryview)):
105107
msg = "Invalid query type: bytes, bytearray and memoryview are forbidden"
106108
raise TypeError(msg)

0 commit comments

Comments
 (0)