MCPcopy Index your code
hub / github.com/github/spec-kit / _safe_compare

Function _safe_compare

src/specify_cli/workflows/expressions.py:411–431  ·  view source on GitHub ↗

Safely compare two values, coercing types when possible.

(left: Any, right: Any, op: str)

Source from the content-addressed store, hash-verified

409
410
411def _safe_compare(left: Any, right: Any, op: str) -> bool:
412 """Safely compare two values, coercing types when possible."""
413 try:
414 if isinstance(left, str):
415 left = float(left) if "." in left else int(left)
416 if isinstance(right, str):
417 right = float(right) if "." in right else int(right)
418 except (ValueError, TypeError):
419 return False
420 try:
421 if op == ">":
422 return left > right # type: ignore[operator]
423 if op == "<":
424 return left < right # type: ignore[operator]
425 if op == ">=":
426 return left >= right # type: ignore[operator]
427 if op == "<=":
428 return left <= right # type: ignore[operator]
429 except TypeError:
430 return False
431 return False
432
433
434def evaluate_expression(template: str, context: Any) -> Any:

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected