fix(gateway): satisfy mypy on nats/grpc adapters and generated proto code
- nats_consumer/grpc_server: annotate nc/sub/server attrs (were inferred as None-only from __init__, breaking on the real assignment later). - active_read: narrow on 'if names:' instead of the derived 'persisted' bool so mypy sees names as non-Optional inside the publish_reading call. - pyproject: exclude ingestor/proto/ (protoc/grpcio-tools output) from mypy's file walk and skip following it as an import - it's generated, not hand-maintained, and mypy can't see its runtime-built message classes.
This commit is contained in:
@@ -51,7 +51,7 @@ class GrpcServer:
|
||||
self.logger = logger
|
||||
self.port = port
|
||||
self.slot_lookup = slot_lookup
|
||||
self.server = None
|
||||
self.server: grpc.aio.Server | None = None
|
||||
|
||||
async def start(self) -> None:
|
||||
self.server = grpc.aio.server()
|
||||
|
||||
@@ -9,6 +9,8 @@ here. No reconnect logic — nats-py handles reconnection internally.
|
||||
import json
|
||||
|
||||
import nats
|
||||
from nats.aio.client import Client
|
||||
from nats.aio.subscription import Subscription
|
||||
from sientia_do.observability.logger import Logger
|
||||
|
||||
from ingestor.engines.write import WriteEngine
|
||||
@@ -28,8 +30,8 @@ class NatsWriteConsumer:
|
||||
self.logger = logger
|
||||
self.subject = subject
|
||||
self.queue = queue
|
||||
self.nc = None
|
||||
self.sub = None
|
||||
self.nc: Client | None = None
|
||||
self.sub: Subscription | None = None
|
||||
|
||||
async def start(self) -> None:
|
||||
self.nc = await nats.connect(servers=self.nats_url)
|
||||
|
||||
@@ -75,7 +75,7 @@ class ActiveReadEngine(SientiaMonitoring):
|
||||
await self._record_read_lag(source_ts, tags)
|
||||
source_str = self._format_ts(source_ts)
|
||||
persisted = bool(names)
|
||||
if persisted:
|
||||
if names:
|
||||
await self.sink.publish_reading(
|
||||
tag=addr, value=value, timestamp=source_str, names=names
|
||||
)
|
||||
|
||||
@@ -81,6 +81,9 @@ warn_unused_ignores = false
|
||||
warn_no_return = true
|
||||
strict_equality = true
|
||||
ignore_missing_imports = true
|
||||
# Generated protoc/grpcio-tools output - not a checking target, dynamic attrs
|
||||
# mypy can't see (message classes built at runtime from DESCRIPTOR).
|
||||
exclude = ["^ingestor/proto/"]
|
||||
|
||||
# Ignore missing imports for external packages
|
||||
[[tool.mypy.overrides]]
|
||||
@@ -107,6 +110,14 @@ ignore_missing_imports = true
|
||||
module = "pandas.*"
|
||||
ignore_missing_imports = true
|
||||
|
||||
# Generated protoc/grpcio-tools output - not hand-maintained, dynamic attrs
|
||||
# mypy can't see (message classes built at runtime from DESCRIPTOR). Skip
|
||||
# following it entirely so importers see Any instead of false attr-defined errors.
|
||||
[[tool.mypy.overrides]]
|
||||
module = "ingestor.proto.*"
|
||||
ignore_errors = true
|
||||
follow_imports = "skip"
|
||||
|
||||
[tool.pytest.ini_options]
|
||||
testpaths = ["tests"]
|
||||
python_files = ["test_*.py"]
|
||||
|
||||
Reference in New Issue
Block a user