Skip to content

Commit d010d9b

Browse files
observability: replace frozenset lambdas with named factory
Two github-code-quality findings on ``detached_subgraphs`` / ``detached_fan_outs`` defaults addressed via the bot's named-factory suggestion. Previous rounds kept the lambdas with an explanatory comment because ``default_factory=frozenset`` produced ``frozenset[Unknown]`` under pyright strict mode; the named factory ``_empty_str_frozenset() -> frozenset[str]`` carries the explicit return annotation, satisfying both constraints (no lambda; pyright preserves the typed empty frozenset). Removed the explanatory comment along with the lambdas.
1 parent aa17f4b commit d010d9b

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

src/openarmature/observability/otel/observer.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,16 @@ def _read_spec_version() -> str:
9494
return __spec_version__
9595

9696

97+
def _empty_str_frozenset() -> frozenset[str]:
98+
"""Typed empty frozenset factory for ``detached_subgraphs`` /
99+
``detached_fan_outs`` defaults. ``default_factory=frozenset``
100+
alone produces ``frozenset[Unknown]`` under pyright strict
101+
mode; a named factory with the explicit return annotation
102+
preserves the ``frozenset[str]`` typing without falling back to
103+
a lambda."""
104+
return frozenset()
105+
106+
97107
@dataclass
98108
class _OpenSpan:
99109
"""An in-flight span paired with the OTel context token that pinned
@@ -148,13 +158,8 @@ class OTelObserver:
148158
"""
149159

150160
span_processor: SpanProcessor
151-
# Lambda-wrapped factories give pyright the explicit
152-
# ``frozenset[str]`` type — ``default_factory=frozenset``
153-
# alone produces ``frozenset[Unknown]`` which the strict-mode
154-
# config flags. The lambda overhead is negligible (one closure
155-
# call per dataclass instance).
156-
detached_subgraphs: frozenset[str] = field(default_factory=lambda: frozenset[str]())
157-
detached_fan_outs: frozenset[str] = field(default_factory=lambda: frozenset[str]())
161+
detached_subgraphs: frozenset[str] = field(default_factory=_empty_str_frozenset)
162+
detached_fan_outs: frozenset[str] = field(default_factory=_empty_str_frozenset)
158163
disable_llm_spans: bool = False
159164
# Read from the package's ``__spec_version__`` (one of the three
160165
# places the spec version is pinned per CLAUDE.md). Bumping the

0 commit comments

Comments
 (0)