Coverage for fastapi_restly / query / _shared.py: 89%
15 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-02 09:54 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-02 09:54 +0000
1import types
2from typing import Any, Union, get_args, get_origin
5def _escape_like_value(value: str) -> str:
6 """Escape SQL LIKE wildcard characters for literal substring matching."""
7 escaped = value.replace("\\", "\\\\")
8 escaped = escaped.replace("%", "\\%")
9 escaped = escaped.replace("_", "\\_")
10 return escaped
13def _unwrap_optional_annotation(annotation: Any) -> Any:
14 """Unwrap Optional[X] or X | None to X. Returns annotation unchanged otherwise."""
15 origin = get_origin(annotation)
16 if origin not in (types.UnionType, Union):
17 return annotation
19 non_none_args = [arg for arg in get_args(annotation) if arg is not type(None)]
20 if len(non_none_args) == 1: 20 ↛ 22line 20 didn't jump to line 22 because the condition on line 20 was always true
21 return non_none_args[0]
22 return annotation