Skip to content

Commit 3213e92

Browse files
authored
chore: replace type ignores with casting (#291)
replace type ignores with casting Signed-off-by: gruebel <[email protected]>
1 parent f2028f5 commit 3213e92

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

providers/openfeature-provider-flagd/src/openfeature/contrib/provider/flagd/resolvers/grpc.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,11 @@ def _convert_context(
391391
if evaluation_context:
392392
try:
393393
s["targetingKey"] = evaluation_context.targeting_key
394-
s.update(evaluation_context.attributes) # type: ignore[arg-type]
394+
s.update(
395+
typing.cast(
396+
"typing.Mapping[str, typing.Any]", evaluation_context.attributes
397+
)
398+
)
395399
except ValueError as exc:
396400
message = (
397401
"could not serialize evaluation context to google.protobuf.Struct"

providers/openfeature-provider-flagd/src/openfeature/contrib/provider/flagd/resolvers/process/targeting.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import time
24
import typing
35

@@ -31,9 +33,11 @@ def targeting(
3133
if not isinstance(targeting, dict):
3234
raise ParseError(f"Invalid 'targeting' value in flag: {targeting}")
3335

34-
json_logic_context = evaluation_context.attributes if evaluation_context else {}
35-
json_logic_context["$flagd"] = {"flagKey": key, "timestamp": int(time.time())} # type: ignore[index]
36-
json_logic_context["targetingKey"] = ( # type: ignore[index]
36+
json_logic_context: dict[str, typing.Any] = (
37+
dict(evaluation_context.attributes) if evaluation_context else {}
38+
)
39+
json_logic_context["$flagd"] = {"flagKey": key, "timestamp": int(time.time())}
40+
json_logic_context["targetingKey"] = (
3741
evaluation_context.targeting_key if evaluation_context else None
3842
)
3943
return jsonLogic(targeting, json_logic_context, OPERATORS)

providers/openfeature-provider-flagd/tests/test_targeting.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from math import floor
88

99
import pytest
10-
from json_logic import builtins, jsonLogic # type: ignore[import-untyped]
10+
from json_logic import builtins, jsonLogic
1111

1212
from openfeature.contrib.provider.flagd.resolvers.process.custom_ops import (
1313
ends_with,

0 commit comments

Comments
 (0)