feat(stdlib): expose Python type references and dict/list constructors in Builtins#291
Merged
feat(stdlib): expose Python type references and dict/list constructors in Builtins#291
Conversation
…s in Builtins Closes #290. Adds the missing pieces in `Fable.Python.Builtins` that downstream interop libraries (Thoth.Json.Python, Fable.TypedJson) currently work around with private `[<Emit>]` declarations: - Type value references (`pyInt`, `pyFloat`, `pyBool`, `pyStr`, `pyBytes`, `pyList`, `pyDict`, `pyTuple`, `pySet`) for use as the second argument to `Fable.Core.PyInterop.pyInstanceof`. The `py` prefix avoids colliding with F#/.NET built-in types. - `pyNone` value for Python's `None` singleton, useful as a JSON-null sentinel and at interop sites that need an explicit None. - `bool`, `dict`, and `list` constructors on `Builtins.IExports`, completing the set alongside the existing `int`/`float`/`str`/`bytes` constructors. `dict` and `list` are typed to return `Dictionary<string,'V>` and `ResizeArray<'T>` respectively to stay idiomatic per BINDINGS_GUIDE.md. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This was referenced May 2, 2026
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.
Closes #290.
Summary
Fable.Python.Builtinsexposesint,float,str,bytes,len,isinstance, etc. as methods onIExports, but the type values themselves (theint/dict/listPython objects) and thedict()/list()constructors weren't exposed. Downstream libraries like Thoth.Json.Python and Fable.TypedJson currently redeclare them privately as[<Emit>]boilerplate.Changes
Type references (top-level
letbindings inBuiltins)For use with
Fable.Core.PyInterop.pyInstanceof:pyInt,pyFloat,pyBool,pyStr,pyBytespyList,pyDict,pyTuple,pySetpyNone— Python'sNonesingleton, typed asobjThe
pyprefix is necessary becauseint,float,bool,str,list,dict, etc. would shadow F#/.NET built-in types.New constructors on
Builtins.IExportsbool: obj -> bool— completing the set alongsideint/float/strdict: unit -> Dictionary<string, obj>dict: IEnumerable<string * 'V> -> Dictionary<string, 'V>— generic in'Vlist: IEnumerable<'T> -> ResizeArray<'T>Dictionary<string,'V>andResizeArray<'T>are used (rather thanobj) to stay idiomatic perBINDINGS_GUIDE.md— these are the F# types that Fable maps to Python's nativedictandlist.Result
Downstream consumers can now drop the private
[<Emit>]boilerplate and write:Test plan
test/TestBuiltins.fscoveringbool,dict()empty,dictfrom pairs,list,pyInstanceofagainst every type reference, andpyNonejust test-python)isinstance(v, int),builtins.dict(),None, etc. — exactly what the issue requested🤖 Generated with Claude Code