Skip to content

Commit

Permalink
Add a fast path to get_str_query for dict and str (#1401)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Oct 30, 2024
1 parent 8ce8d67 commit 71d171e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES/1401.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improved performance of passing a `dict` or `str` to :py:meth:`~yarl.URL.extend_query` -- by :user:`bdraco`.
6 changes: 4 additions & 2 deletions yarl/_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 71d171e

Please sign in to comment.