Skip to content

Commit

Permalink
Improve performance of with_query when passing an empty value (#1328)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Oct 18, 2024
1 parent 8e445f4 commit a071e6d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES/1328.misc.rst
6 changes: 4 additions & 2 deletions yarl/_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -1342,7 +1342,7 @@ def _query_var(v: QueryVariable) -> str:

@classmethod
def _get_str_query_from_iterable(
cls, items: Iterable[tuple[Union[str, istr], str]]
cls, items: Iterable[tuple[Union[str, istr], SimpleQuery]]
) -> str:
"""Return a query string from an iterable.
Expand All @@ -1364,7 +1364,7 @@ def _get_str_query_from_iterable(
def _get_str_query(cls, *args: Any, **kwargs: Any) -> Union[str, None]:
query: Union[str, Mapping[str, QueryVariable], None]
if kwargs:
if len(args) > 0:
if args:
raise ValueError(
"Either kwargs or single query parameter must be present"
)
Expand All @@ -1376,6 +1376,8 @@ def _get_str_query(cls, *args: Any, **kwargs: Any) -> Union[str, None]:

if query is None:
return None
if not query:
return ""
if isinstance(query, Mapping):
return cls._get_str_query_from_sequence_iterable(query.items())
if isinstance(query, str):
Expand Down

0 comments on commit a071e6d

Please sign in to comment.