🚀 Feature
I propose some functionality be added to pyodide.ffi.to_js to allow Python None values to be translated into null values rather than undefined values.
Motivation
Currently pyodide.ffi.to_js converts all encountered None values to undefined on the JS side. In certain scenarios this is problematic because some downstream consumer of the converted value might expect null rather than undefined. One such case are Bokeh event messages. When converting the events generated by Bokeh in Python into JS objects that can be applied to a Bokeh Document they often contain serialized copies of the Model attribute values that have changed and Bokeh's property system makes a very clear distinction between a null value and an undefined value. Bokeh makes this distinction because undefined implies the value has not been set, while null is a perfectly valid value.
Pitch
Ideally I'd simply provide some way to override mappings for specific types, e.g. {None: pyodide.code.run_js('null')}. Alternatively I'd also be happy for a custom dict_converter to be made available that allows overriding the translation.
🚀 Feature
I propose some functionality be added to
pyodide.ffi.to_jsto allow PythonNonevalues to be translated intonullvalues rather thanundefinedvalues.Motivation
Currently
pyodide.ffi.to_jsconverts all encounteredNonevalues toundefinedon the JS side. In certain scenarios this is problematic because some downstream consumer of the converted value might expectnullrather thanundefined. One such case are Bokeh event messages. When converting the events generated by Bokeh in Python into JS objects that can be applied to a Bokeh Document they often contain serialized copies of the Model attribute values that have changed and Bokeh's property system makes a very clear distinction between anullvalue and anundefinedvalue. Bokeh makes this distinction becauseundefinedimplies the value has not been set, whilenullis a perfectly valid value.Pitch
Ideally I'd simply provide some way to override mappings for specific types, e.g.
{None: pyodide.code.run_js('null')}. Alternatively I'd also be happy for a customdict_converterto be made available that allows overriding the translation.