Skip to content

fix(stdlib): align Json.getCases return type with Python output#279

Merged
dbrattli merged 1 commit intomainfrom
fix/json-pyright-array-type
Apr 26, 2026
Merged

fix(stdlib): align Json.getCases return type with Python output#279
dbrattli merged 1 commit intomainfrom
fix/json-pyright-array-type

Conversation

@dbrattli
Copy link
Copy Markdown
Collaborator

Summary

  • Fixes Pyright type error in transpiled Json.fs: getCases returns Any | list[Unknown] instead of Array[str] #278: pyright error Type "Any | list[Unknown]" is not assignable to declared type "Array" in the generated build/stdlib/json.py.
  • Root cause: getCases was annotated string array (FSharpArray) in F#, but Fable union types' cases() method actually returns a Python list — and the emit's lambda: [] fallback returns a list too. Switched the F# return type to ResizeArray<string> (which maps to list[str]) and updated the call site to use .Count instead of .Length. Both compile to len(...), so runtime behavior is identical.
  • Wires pyright into CI to prevent regressions:
    • New just pyright recipe (depends on build, runs uv run pyright).
    • New CI step in build-and-test.yml between build and test.
    • [tool.pyright] scoped to build/stdlib and switched to standard mode (matches what downstream consumers run).
    • Disabled reportUnusedImport and reportInvalidTypeVarUse — both are Fable codegen artifacts (unused UNIT imports, single-occurrence TypeVars from F# generics), not bindings issues.
    • Bumped pyright >=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

🤖 Generated with Claude Code

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>
@dbrattli dbrattli merged commit 32691fd into main Apr 26, 2026
9 checks passed
@dbrattli dbrattli deleted the fix/json-pyright-array-type branch April 26, 2026 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pyright type error in transpiled Json.fs: getCases returns Any | list[Unknown] instead of Array[str]

1 participant