Coverage for functions \ flipdare \ search \ core \ filter \ filter_guards.py: 92%
12 statements
« prev ^ index » next coverage.py v7.13.0, created at 2026-05-08 12:22 +1000
« prev ^ index » next coverage.py v7.13.0, created at 2026-05-08 12:22 +1000
1# Copyright (c) 2026 Flipdare Pty Ltd. All rights reserved.
2#
3# This file is part of Flipdare's proprietary software and contains
4# confidential and copyrighted material. Unauthorised copying,
5# modification, distribution, or use of this file is strictly
6# prohibited without prior written permission from Flipdare Pty Ltd.
7#
8# This software includes third-party components licensed under MIT,
9# BSD, and Apache 2.0 licences. See THIRD_PARTY_NOTICES for details.
10#
12from enum import StrEnum
13from typing import TypeGuard
15from flipdare.search.core.filter._complex_filter import ComplexFilter
16from flipdare.search.core.filter._simple_filter import SimpleFilter
18type QueryFilterType[T: StrEnum] = SimpleFilter[T] | ComplexFilter[T]
21class FilterGuards:
22 @staticmethod
23 def is_complex_filter[T: StrEnum](
24 filter_by: QueryFilterType[T] | None,
25 ) -> TypeGuard[ComplexFilter[T]]:
26 """Type guard to narrow a filter to ComplexFilter[T]."""
27 return isinstance(filter_by, ComplexFilter)
29 @staticmethod
30 def is_simple_filter[T: StrEnum](
31 filter_by: QueryFilterType[T] | None,
32 ) -> TypeGuard[SimpleFilter[T]]:
33 """Type guard to narrow a filter to SimpleFilter[T]."""
34 return isinstance(filter_by, SimpleFilter)