PY: type-check fixes for python-us-core example (mypy clean) - #180
Merged
Conversation
This was referenced Jun 18, 2026
ryukzak
force-pushed
the
py-mypy-example-fixes
branch
from
June 18, 2026 09:22
a15252c to
b56d8c0
Compare
MikhailArtemyev
approved these changes
Jun 18, 2026
Non-type-discriminated slice getters declared a single flat return type but returned the raw element object for mode="raw", so accessing raw attributes failed type checking. Emit @overload signatures (mirroring extension getters): default -> flat type, Literal["raw"] -> element type. Import the slice element type and Literal/overload/Any accordingly.
The raw-mode slice getters now type-check via overloads, so the # type: ignore[call-arg] comments (which never matched the real attr-defined error anyway) are no longer needed.
Type-discriminated slices use the typed base type directly (no flat-dict form), so passing dict literals to set_patient_entry mismatched the signature. Build BundleEntry(resource=...) like the other cases, and read entry.resource directly instead of the dead dict fallback.
Building args via dict(...) erased per-key value types to object, so splatting into create()/create_resource() and indexing into set_identifier()/set_name() mismatched the typed signatures. Bind identifier/name as locals and pass them directly.
mypy only scanned generated code, so type errors in the hand-written example tests went unnoticed. Widen the scope to the whole example dir, matching the other python example targets (which run mypy over '.').
ryukzak
force-pushed
the
py-mypy-example-fixes
branch
from
June 18, 2026 13:05
b56d8c0 to
2f4e4f4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Makes
mypy .onexamples/python-us-coreclean (0 errors). The bulk of prior noise came from a broken localmypy.ini; the genuine 18 errors are fixed here.Slice getter raw-mode overloads
The Python profile generator emitted typed
@overloads for extension getters but not for slice getters — plain slice getters declared a single flat return type yet returned the raw element object formode="raw", so accessing raw attributes failed type checking.Slice getters now mirror the extension pattern (
Literal["raw"]→ element type), and the slice element type /Literal/overload/Anyimports are threaded through.Motivation:
get_systolic("raw").value_quantityno longer fails[attr-defined].elementTypeIdis now imported explicitly for plain slices (previously compiled only because accessors happened to import the same type).Example test cleanups
# type: ignore[call-arg]on raw slice getters (now type-check via overloads; the ignores never matched the realattr-definederror).BundleEntry(resource=...)instead of dict literals — type-discriminated slices use the typed base directly, with no flat-dict form — and readentry.resourcedirectly instead of the dead dict fallback.identifier/nameas locals and pass them directly instead of an untypeddict(...)splat (which erased value types toobject).Regenerated
fhir_types/for the example.