Skip to content

Commit c21eae4

Browse files
committed
adjust protobuf hatch plugin and mypy
Signed-off-by: gruebel <[email protected]>
1 parent dd1a212 commit c21eae4

File tree

5 files changed

+44
-5
lines changed

5 files changed

+44
-5
lines changed

.github/workflows/build.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ jobs:
4545
run: hatch build
4646
working-directory: ${{ matrix.package }}
4747

48+
- name: Type checking
49+
if: matrix.package == 'providers/openfeature-provider-flagd'
50+
working-directory: ${{ matrix.package }}
51+
run: hatch run mypy
52+
4853
- name: Test with pytest
4954
run: hatch test -c
5055
working-directory: ${{ matrix.package }}

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ repos:
2929
- mmh3
3030
- semver
3131
- panzi-json-logic
32-
exclude: proto|tests
32+
exclude: providers/openfeature-provider-flagd|tests

mypy.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[mypy]
2-
files = hooks,providers
2+
files = hooks,providers/openfeature-provider-ofrep
33
exclude = proto|tests
44
untyped_calls_exclude = flagd.proto
55

providers/openfeature-provider-flagd/pyproject.toml

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ classifiers = [
1717
]
1818
keywords = []
1919
dependencies = [
20-
"openfeature-sdk>=0.4.0",
20+
"openfeature-sdk>=0.6.0",
2121
"grpcio>=1.60.0",
2222
"protobuf>=4.25.2",
2323
"mmh3>=4.1.0",
@@ -40,6 +40,9 @@ dependencies = [
4040
"testcontainers",
4141
"asserts",
4242
"grpcio-health-checking==1.60.0",
43+
"mypy[faster-cache]>=1.13.0",
44+
"types-protobuf",
45+
"types-pyyaml",
4346
]
4447
pre-install-commands = [
4548
"hatch build",
@@ -93,3 +96,30 @@ omit = [
9396
"src/openfeature/contrib/provider/flagd/proto/*",
9497
"tests/**",
9598
]
99+
100+
[tool.mypy]
101+
mypy_path = "src"
102+
files = "src"
103+
exclude = [
104+
"src/openfeature/contrib/provider/flagd/protobuf"
105+
]
106+
107+
namespace_packages = true
108+
explicit_package_bases = true
109+
local_partial_types = true
110+
pretty = true
111+
112+
strict = true
113+
disallow_any_generics = false
114+
115+
[[tool.mypy.overrides]]
116+
module = [
117+
"grpc"
118+
]
119+
ignore_missing_imports = true
120+
121+
[[tool.mypy.overrides]]
122+
module = [
123+
"openfeature.contrib.provider.flagd.protobuf.*"
124+
]
125+
follow_imports = "silent"

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020

2121
from ..config import Config
2222
from ..flag_type import FlagType
23+
from ..protobuf.flagd.evaluation.v1 import evaluation_pb2, evaluation_pb2_grpc
24+
25+
if typing.TYPE_CHECKING:
26+
from google.protobuf.message import Message
2327

2428
T = typing.TypeVar("T")
2529

@@ -31,7 +35,7 @@ def __init__(self, config: Config):
3135
grpc.secure_channel if self.config.tls else grpc.insecure_channel
3236
)
3337
self.channel = channel_factory(f"{self.config.host}:{self.config.port}")
34-
self.stub = evaluation_pb2_grpc.ServiceStub(self.channel)
38+
self.stub = evaluation_pb2_grpc.ServiceStub(self.channel) # type: ignore[no-untyped-call]
3539

3640
def shutdown(self) -> None:
3741
self.channel.close()
@@ -94,7 +98,7 @@ def _resolve( # noqa: PLR0915
9498
evaluation_pb2.ResolveFloatRequest,
9599
]
96100
if flag_type == FlagType.BOOLEAN:
97-
request = evaluation_pb2.ResolveBooleanRequest(
101+
request: Message = evaluation_pb2.ResolveBooleanRequest(
98102
flag_key=flag_key, context=context
99103
)
100104
response = self.stub.ResolveBoolean(request, **call_args)

0 commit comments

Comments
 (0)