fix(stdlib): align Json.getCases return type with Python output#279
Merged
fix(stdlib): align Json.getCases return type with Python output#279
Conversation
The F# return type `string array` for `getCases` was inaccurate — Fable union types' `cases()` static method returns `list[str]`, not an FSharpArray. Pyright flagged the resulting `cases: Array[str] = ...` assignment as a type error in the generated Python (issue #278). Change the return type to `ResizeArray<string>` (which maps to Python `list`) and update the call site to use `.Count` instead of `.Length`. Both compile to `len(...)` so runtime behavior is unchanged. Also wire up pyright in CI to catch future regressions: add a `just pyright` recipe scoped to `build/stdlib`, run it in the build-and-test workflow, and bump pyright to 1.1.409. Fable codegen-artifact rules (`reportUnusedImport`, `reportInvalidTypeVarUse`) are disabled since those are emitted by the compiler, not the bindings. Closes #278 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
getCasesreturnsAny | list[Unknown]instead ofArray[str]#278: pyright errorType "Any | list[Unknown]" is not assignable to declared type "Array"in the generatedbuild/stdlib/json.py.getCaseswas annotatedstring array(FSharpArray) in F#, but Fable union types'cases()method actually returns a Pythonlist— and the emit'slambda: []fallback returns a list too. Switched the F# return type toResizeArray<string>(which maps tolist[str]) and updated the call site to use.Countinstead of.Length. Both compile tolen(...), so runtime behavior is identical.just pyrightrecipe (depends onbuild, runsuv run pyright).build-and-test.ymlbetween build and test.[tool.pyright]scoped tobuild/stdliband switched tostandardmode (matches what downstream consumers run).reportUnusedImportandreportInvalidTypeVarUse— both are Fable codegen artifacts (unusedUNITimports, single-occurrence TypeVars from F# generics), not bindings issues.>=1.1.408→>=1.1.409.Verified by stashing the Json.fs fix and re-running
just pyright: the exact error from issue #278 reproduces. With the fix applied,0 errors, 0 warnings. All 524 Python tests still pass.Test plan
just buildsucceedsjust pyrightreports0 errors, 0 warnings, 0 informationsjust test-python— all 524 tests pass (17 json tests included)just pyrightreproduce the originalreportAssignmentTypeerror from Pyright type error in transpiled Json.fs:getCasesreturnsAny | list[Unknown]instead ofArray[str]#278🤖 Generated with Claude Code