Skip to content

Commit a1b679a

Browse files
committed
fix typing
1 parent 7d428da commit a1b679a

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

flag_engine/segments/evaluator.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -235,14 +235,14 @@ def _matches_context_value(
235235

236236

237237
def _evaluate_not_contains(
238-
segment_value: str | None,
238+
segment_value: typing.Optional[str],
239239
context_value: ContextValue,
240240
) -> bool:
241241
return isinstance(context_value, str) and str(segment_value) not in context_value
242242

243243

244244
def _evaluate_regex(
245-
segment_value: str | None,
245+
segment_value: typing.Optional[str],
246246
context_value: ContextValue,
247247
) -> bool:
248248
return (
@@ -252,7 +252,7 @@ def _evaluate_regex(
252252

253253

254254
def _evaluate_modulo(
255-
segment_value: str | None,
255+
segment_value: typing.Optional[str],
256256
context_value: ContextValue,
257257
) -> bool:
258258
if not isinstance(context_value, (int, float)):
@@ -271,7 +271,9 @@ def _evaluate_modulo(
271271
return context_value % divisor == remainder
272272

273273

274-
def _evaluate_in(segment_value: str | None, context_value: ContextValue) -> bool:
274+
def _evaluate_in(
275+
segment_value: typing.Optional[str], context_value: ContextValue
276+
) -> bool:
275277
if segment_value:
276278
try:
277279
in_values = json.loads(segment_value)
@@ -294,11 +296,11 @@ def _evaluate_in(segment_value: str | None, context_value: ContextValue) -> bool
294296

295297
def _context_value_typed(
296298
func: typing.Callable[..., bool],
297-
) -> typing.Callable[[str | None, ContextValue], bool]:
299+
) -> typing.Callable[[typing.Optional[str], ContextValue], bool]:
298300
@wraps(func)
299301
def inner(
300-
segment_value: str | None,
301-
context_value: ContextValue | semver.Version,
302+
segment_value: typing.Optional[str],
303+
context_value: typing.Union[ContextValue, semver.Version],
302304
) -> bool:
303305
with suppress(TypeError, ValueError):
304306
if isinstance(context_value, str) and is_semver(segment_value):
@@ -313,7 +315,7 @@ def inner(
313315

314316

315317
MATCHERS_BY_OPERATOR: dict[
316-
ConditionOperator, typing.Callable[[str | None, ContextValue], bool]
318+
ConditionOperator, typing.Callable[[typing.Optional[str], ContextValue], bool]
317319
] = {
318320
constants.NOT_CONTAINS: _evaluate_not_contains,
319321
constants.REGEX: _evaluate_regex,

tests/unit/segments/test_segments_evaluator.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import typing
2+
13
import pytest
24
from pytest_lazy_fixtures import lf
35
from pytest_mock import MockerFixture
@@ -454,7 +456,7 @@ def test_context_in_segment_is_set_and_is_not_set(
454456
)
455457
def test_segment_condition_matches_context_value(
456458
operator: ConditionOperator,
457-
trait_value: None | int | str | float,
459+
trait_value: typing.Union[None, int, str, float],
458460
condition_value: str,
459461
expected_result: bool,
460462
) -> None:
@@ -609,7 +611,7 @@ def test_context_matches_condition(
609611
],
610612
)
611613
def test_segment_condition_matches_context_value_for_modulo(
612-
trait_value: int | float | str | bool,
614+
trait_value: typing.Union[int, float, str, bool],
613615
condition_value: str,
614616
expected_result: bool,
615617
) -> None:

tests/unit/utils/test_utils_hashing.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import itertools
2+
import typing
23
import uuid
34
from unittest import mock
45

@@ -17,7 +18,7 @@
1718
),
1819
)
1920
def test_get_hashed_percentage_for_object_ids_is_number_between_0_inc_and_100_exc(
20-
object_ids: list[uuid.UUID | int | str],
21+
object_ids: list[typing.Union[uuid.UUID, int, str]],
2122
) -> None:
2223
assert 100 > get_hashed_percentage_for_object_ids(object_ids) >= 0
2324

@@ -32,7 +33,7 @@ def test_get_hashed_percentage_for_object_ids_is_number_between_0_inc_and_100_ex
3233
),
3334
)
3435
def test_get_hashed_percentage_for_object_ids_is_the_same_each_time(
35-
object_ids: list[uuid.UUID | int | str],
36+
object_ids: list[typing.Union[uuid.UUID, int, str]],
3637
) -> None:
3738
# When
3839
result_1 = get_hashed_percentage_for_object_ids(object_ids)

0 commit comments

Comments
 (0)