reflex/tests/utils
benedikt-bartscher e42d4ed9ef
[REF-3009] type transforming serializers (#3227)
* wip type transforming serializers

* old python sucks

* typing fixups

* Expose the `to` parameter on `rx.serializer` for type conversion

Serializers can also return a tuple of `(serialized_value, type)`, if both ways
are specified, then the returned value MUST match the `to` parameter.

When initializing a new rx.Var, if `_var_is_string` is not specified and the serializer returns a `str` type, then mark `_var_is_string=True` to indicate that the Var should be treated like a string literal.

Include datetime, color, types, and paths as "serializing to str" type.

Avoid other changes at this point to reduce fallout from this change:

  Notably, the `serialize_str` function does NOT cast to `str`, which
  would cause existing code to treat all Var initialized with a str as a
  str literal even though this was NOT the default before.

Update test cases to accomodate these changes.

* Raise deprecation warning for rx.Var.create with string literal

In the future, we will treat strings as string literals in the JS code. To get
a Var that is not treated like a string, pass _var_is_string=False.

This will allow our serializers to automatically identify cast string literals
with less special cases (and the special cases need to be explicitly
identified).

* Add test case for mismatched serialized types

* fix old python

* Remove serializer returning a tuple feature

Simplify the logic; instead of making a wrapper function that returns
a tuple, just save the type conversions in a separate global.

* Reset the LRU cache when adding new serializers

---------

Co-authored-by: Masen Furer <m_github@0x26.net>
2024-06-07 09:50:10 -07:00
..
__init__.py Add serializers for different var types (#1816) 2023-09-15 17:19:26 -07:00
test_format.py Layout property not pushed through on rx.plotly (#3394) 2024-05-31 11:48:43 -07:00
test_imports.py fix name for import var when is default and add tests (#2214) 2023-11-26 12:46:43 -08:00
test_serializers.py [REF-3009] type transforming serializers (#3227) 2024-06-07 09:50:10 -07:00
test_types.py allow optional props with None default value (#3179) 2024-05-01 13:33:38 -07:00
test_utils.py [REF-2141] Custom component command improvements (#2807) 2024-03-07 20:42:22 -08:00