Loading behave_utils/json.py +4 −1 Original line number Diff line number Diff line Loading @@ -10,6 +10,7 @@ JSON classes for container types (objects and arrays) from __future__ import annotations from types import GenericAlias from typing import Any from typing import Callable from typing import TypeVar Loading @@ -35,13 +36,15 @@ class JSONPathMixin: @overload def path(self, path: str, kind: type[T], convert: Callable[[T], C]) -> C: ... def path(self, path: str, kind: type[T], convert: Callable[[T], C]|None = None) -> T|C: def path(self, path: str, kind: type[T]|GenericAlias, convert: Callable[[T], C]|None = None) -> T|C: result = JSONPath(path).parse(self) if "*" not in path: try: result = result[0] except IndexError: raise KeyError(path) from None if isinstance(kind, GenericAlias): kind = kind.__origin__ if not isinstance(result, kind): raise TypeError(f"{path} is wrong type; expected {kind}; got {type(result)}") if convert is None: Loading Loading
behave_utils/json.py +4 −1 Original line number Diff line number Diff line Loading @@ -10,6 +10,7 @@ JSON classes for container types (objects and arrays) from __future__ import annotations from types import GenericAlias from typing import Any from typing import Callable from typing import TypeVar Loading @@ -35,13 +36,15 @@ class JSONPathMixin: @overload def path(self, path: str, kind: type[T], convert: Callable[[T], C]) -> C: ... def path(self, path: str, kind: type[T], convert: Callable[[T], C]|None = None) -> T|C: def path(self, path: str, kind: type[T]|GenericAlias, convert: Callable[[T], C]|None = None) -> T|C: result = JSONPath(path).parse(self) if "*" not in path: try: result = result[0] except IndexError: raise KeyError(path) from None if isinstance(kind, GenericAlias): kind = kind.__origin__ if not isinstance(result, kind): raise TypeError(f"{path} is wrong type; expected {kind}; got {type(result)}") if convert is None: Loading