reflex/tests/components/core
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 rx.color to work with conditional vars (#2546) 2024-02-08 11:45:15 -08:00
test_banner.py Radix 3.0 (#3159) 2024-04-25 08:33:29 -07:00
test_colors.py [REF-3009] type transforming serializers (#3227) 2024-06-07 09:50:10 -07:00
test_cond.py fix rx.cond with ComputedVars and use union type (#3336) 2024-05-19 12:14:46 -07:00
test_debounce.py generate pyi files when building/publishing 3rd party component (#2945) 2024-03-29 09:54:21 -07:00
test_foreach.py [REF-2821]Improve Dynamic Imports (#3345) 2024-05-31 16:43:10 +00:00
test_html.py [REF-2574] Default width for Stack (+children) and default padding for container (#3104) 2024-04-30 13:15:57 -07:00
test_match.py generate pyi files when building/publishing 3rd party component (#2945) 2024-03-29 09:54:21 -07:00
test_responsive.py generate pyi files when building/publishing 3rd party component (#2945) 2024-03-29 09:54:21 -07:00
test_upload.py Refactor upload component and add styled upload component (#3035) 2024-04-24 13:45:22 -07:00