Skip to content

Commit

Permalink
annotationS
Browse files Browse the repository at this point in the history
2
  • Loading branch information
michaelboulton committed Jan 24, 2024
1 parent d85a0ac commit 1dcab85
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions tavern/_core/dict_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import string
import typing
from collections.abc import Collection
from typing import Any, Dict, Iterator, List, Mapping, Tuple, Union
from typing import Any, Dict, Iterator, List, Mapping, Optional, Tuple, Union

import box
import jmespath
Expand All @@ -27,7 +27,7 @@
logger: logging.Logger = logging.getLogger(__name__)


def _check_and_format_values(to_format, box_vars: Mapping[str, Any]) -> str:
def _check_and_format_values(to_format: str, box_vars: Mapping[str, Any]) -> str:
formatter = string.Formatter()
would_format = formatter.parse(to_format)

Expand Down Expand Up @@ -57,7 +57,7 @@ def _check_and_format_values(to_format, box_vars: Mapping[str, Any]) -> str:
return to_format.format(**box_vars)


def _attempt_find_include(to_format: str, box_vars: box.Box):
def _attempt_find_include(to_format: str, box_vars: box.Box) -> Optional[str]:
formatter = string.Formatter()
would_format = list(formatter.parse(to_format))

Expand Down Expand Up @@ -91,15 +91,18 @@ def _attempt_find_include(to_format: str, box_vars: box.Box):

would_replace = formatter.get_field(field_name, [], box_vars)[0]

return formatter.convert_field(would_replace, conversion) # type: ignore
if conversion is None:
return would_replace

return formatter.convert_field(would_replace, conversion)


T = typing.TypeVar("T", str, Dict, List, Tuple)


def format_keys(
val: T,
variables: Mapping,
variables: Union[Mapping, Box],
*,
no_double_format: bool = True,
dangerously_ignore_string_format_errors: bool = False,
Expand Down

0 comments on commit 1dcab85

Please sign in to comment.