Skip to content

Commit

Permalink
Move local imports and add typing
Browse files Browse the repository at this point in the history
  • Loading branch information
krestenlaust committed Jan 13, 2025
1 parent 43bd849 commit 96ee92b
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions openapi/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Any
from urllib.parse import parse_qs, urlencode, urlparse, urlunparse


def update_dictionary_values(original: dict[Any, Any], replacement: dict[Any, Any]) -> None:
Expand All @@ -11,15 +12,13 @@ def update_dictionary_values(original: dict[Any, Any], replacement: dict[Any, An
original.update({k: v for k, v in replacement.items() if k in original})


def update_query_parameter_values(url_string: str, new_parameter_values: dict) -> str:
def update_query_parameter_values(url_string: str, new_parameter_values: dict[str, Any]) -> str:
"""
Updates query parameters with new parameter values from new_parameter_values.
:param url_string: The URL path of which to modify query parameters.
:param new_parameter_values: The dictionary with new query parameter values.
:return: The URL with updated query parameter.
"""
from urllib.parse import parse_qs, urlencode, urlparse, urlunparse

parsed_url = urlparse(url_string)

qs_dict = parse_qs(parsed_url.query, keep_blank_values=True)
Expand All @@ -29,4 +28,4 @@ def update_query_parameter_values(url_string: str, new_parameter_values: dict) -

parsed_url = parsed_url._replace(query=updated_qs)

return str(urlunparse(parsed_url))
return str(urlunparse(parsed_url))

0 comments on commit 96ee92b

Please sign in to comment.