From d88c1d7ac4f9d4973603ee8d256a065bc537c3b7 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 20 Jun 2026 18:11:32 +0000 Subject: [PATCH] docs: narrow Optional radiated_noise in explore_platform example The shipped scratch file triggered a Pylance reportOptionalMemberAccess warning because radiated_noise is Optional on the schema. Add an assert to narrow it (the same idiom the pipeline uses, and an instructive one), so learners see clean, fully-typed access. Sync the README walkthrough. Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_01AHAkhfmfcCdWTHZuvRcJNF --- README.md | 7 ++++--- examples/explore_platform.py | 9 +++++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 78c3a07..696149e 100644 --- a/README.md +++ b/README.md @@ -63,9 +63,10 @@ meets the schema**. Feel the difference yourself. **First, experience editor autocomplete.** Open [`examples/explore_platform.py`](examples/explore_platform.py) in VS Code (the Codespace -ships Pylance). Find the `# platform.` line, delete the `#`, put your cursor right after the -dot, and type: VS Code pops up the object's *declared* attributes (`radiated_noise`, -`sensors`, …) — statically, before the code has even run. Keep drilling +ships Pylance). Find the `# platform.radiated_noise.` line, delete the `#`, put your cursor +right after the dot, and type: VS Code pops up the object's *declared* attributes +(`band`, …) — statically, before the code has even run. Try `platform.` too for the +top-level attributes (`radiated_noise`, `sensors`, …). Keep drilling (`platform.radiated_noise.band[0].`) and it completes all the way down. That instant, schema-shaped autocomplete is the real payoff of declared fields. Run the file any time with: diff --git a/examples/explore_platform.py b/examples/explore_platform.py index 10db168..4d79260 100644 --- a/examples/explore_platform.py +++ b/examples/explore_platform.py @@ -12,10 +12,15 @@ # its type from the function's return annotation — no need to run anything first. platform = build.build_platform_from_file("examples/calculation_input.xml") +# `radiated_noise` is Optional on the schema (it may be absent), so the type checker treats +# it as possibly-None. The pipeline's gates guarantee it is populated here; this assert tells +# Pylance the same thing — after it, `.band` is a clean, fully-typed access (no squiggle). +assert platform.radiated_noise is not None + # TODO: put your cursor at the end of the next line, after the dot, and type. -# VS Code should pop up the declared attributes (radiated_noise, sensors, ...). +# VS Code should pop up the declared attributes (band, ...). # Keep drilling — `platform.radiated_noise.band[0].` completes too, all the way down. -# platform. +# platform.radiated_noise. # A couple of fully-typed accesses to confirm it ran (delete or extend these freely): print("type:", type(platform).__name__)