Skip to content

fix(stdlib): builtins.map multi-iterable binding + add coverage for untested builtins#292

Merged
dbrattli merged 3 commits intomainfrom
repo-assist/tests-builtins-coverage-2026-05-03-1ab6621ef5a6a7a9
May 3, 2026
Merged

fix(stdlib): builtins.map multi-iterable binding + add coverage for untested builtins#292
dbrattli merged 3 commits intomainfrom
repo-assist/tests-builtins-coverage-2026-05-03-1ab6621ef5a6a7a9

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot commented May 3, 2026

Summary

Adds tests for builtins that were bound but had no coverage, and fixes a binding bug uncovered by the new tests.

🐞 Bug fix

builtins.map 2- and 3-iterable overloads — the function parameter was typed as 'T1 * 'T2 -> 'T3 (tuple-input), which Fable compiles to a Python function expecting a single tuple argument. But Python's map(f, it1, it2) calls f(a, b) positionally, so the overloads failed at runtime with TypeError: takes 1 positional argument but 2 were given. Switched both overloads to System.Func<...>, matching the pattern already used by functools.reduce and itertools.accumulate. Call sites use the natural curried form: builtins.map ((fun a b -> a + b), xs, ys).

🧪 Tests

Adds 17 new [<Fact>] tests covering builtins that had zero coverage:

Function What's tested
abs int and float absolute values
chr / ord ASCII + non-BMP round-trip (☃)
len string length and (Python-native) list length
map 1-, 2-, and 3-iterable overloads
str converts int and bool to string
int string parse, float truncation toward zero (incl. negative)
float string parse and int conversion
isinstance true/false using pyInt/pyStr type references with emitPyExpr
type returns a usable type object
bytes from byte array and from string with encoding (length and byte content)

isinstance/type tests use emitPyExpr to construct genuine Python primitives (per the comment in the existing pyInstanceof test), since F# int/float/bool compile to Fable wrapper classes.

Notes

CI will validate that the Fable-compiled Python passes all assertions.

@dbrattli dbrattli changed the title [Repo Assist] test(stdlib): add coverage for untested builtins (abs, chr/ord, len, map, conversions, isinstance, bytes) test(stdlib): add coverage for untested builtins (abs, chr/ord, len, map, conversions, isinstance, bytes) May 3, 2026
@dbrattli dbrattli marked this pull request as ready for review May 3, 2026 06:09
github-actions Bot and others added 3 commits May 3, 2026 12:01
… map, type conversions, isinstance, bytes

Adds 15 new [<Fact>] tests for builtins that were bound in Builtins.fs
but had no test coverage:
- abs (int and float)
- chr / ord (and round-trip)
- len (list and string)
- map (single and two-iterable overloads)
- str / int / float type conversions
- isinstance / type
- bytes (from byte array and from string with encoding)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
`len` on an F# `int list` fails because FSharpList has no `__len__`;
convert via `builtins.list` instead. Drop the two-iterable `map` case —
the binding's `'T1 * 'T2 -> 'T3` signature compiles to a tuple-input
function but Python's `map` calls `f(a, b)` positionally.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The 2- and 3-iterable overloads typed the function as `'T1 * 'T2 -> 'T3`
(tuple-input), which Fable compiles to a Python function expecting a
single tuple arg. But Python's `map(f, it1, it2)` calls `f(a, b)`
positionally, so calls failed with "takes 1 positional argument but 2
were given". Switching to `System.Func<...>` produces a Python function
with the correct positional arity. Restores the two-iterable test and
adds a three-iterable test.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@dbrattli dbrattli force-pushed the repo-assist/tests-builtins-coverage-2026-05-03-1ab6621ef5a6a7a9 branch from 240b2bf to 2040e42 Compare May 3, 2026 10:06
@dbrattli dbrattli changed the title test(stdlib): add coverage for untested builtins (abs, chr/ord, len, map, conversions, isinstance, bytes) fix(stdlib): builtins.map multi-iterable binding + add coverage for untested builtins May 3, 2026
@dbrattli dbrattli merged commit 663c82a into main May 3, 2026
10 checks passed
@dbrattli dbrattli deleted the repo-assist/tests-builtins-coverage-2026-05-03-1ab6621ef5a6a7a9 branch May 3, 2026 10:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant