Skip to content

Commit 05806b2

Browse files
chore: bring examples under pyright (#43)
VS Code's Pylance surfaces type errors on the example files because they're outside pyright's `[tool.pyright].include` (currently src, tests). Pylance reads the project config, sees the example file isn't in scope, falls back to inferred typing that loses pydantic / openai SDK type info, and emits unknown-member squiggles. Two changes: - pyproject.toml: extend pyright's include to ["src", "tests", "examples"] so the project-wide check covers them and Pylance inherits the same scope. - examples/00-hello-world/main.py: with pyright now seeing the example, the trace() observer's `event.post_state.sources` access becomes a real error. `NodeEvent.post_state` is typed as the base `State`, not the subclass `PipelineState`. Adding an `isinstance(event.post_state, PipelineState)` check narrows the type for static checkers and acts as a defensive guard against any foreign-state observer event the engine might dispatch. All other examples (01-05) come up pyright-clean under project-wide context. Confirmed via uv run pyright = 0 errors after the changes.
1 parent 2ecb7b1 commit 05806b2

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

examples/00-hello-world/main.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,12 @@ def route(state: PipelineState) -> str:
178178
async def trace(event: NodeEvent) -> None:
179179
# OpenAIProvider emits NodeEvent-shaped events for LLM-span
180180
# tracking under a sentinel namespace; those have post_state=None.
181-
# Filter to events that carry a state snapshot before reading it.
182-
if event.phase == "completed" and event.error is None and event.post_state is not None:
181+
# Filter to events that carry a PipelineState snapshot before
182+
# reading it. The isinstance check both narrows the type for
183+
# static checkers (post_state is typed as the base State, not
184+
# PipelineState) and acts as a defensive guard against any
185+
# foreign-state observer event the engine might dispatch.
186+
if event.phase == "completed" and event.error is None and isinstance(event.post_state, PipelineState):
183187
print(f"{event.node_name}: sources={event.post_state.sources}")
184188

185189

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ examples = [
7979
packages = ["src/openarmature"]
8080

8181
[tool.pyright]
82-
include = ["src", "tests"]
82+
include = ["src", "tests", "examples"]
8383
pythonVersion = "3.12"
8484
typeCheckingMode = "strict"
8585
reportMissingTypeStubs = false

0 commit comments

Comments
 (0)