reflex/tests
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
..
compiler [REF-3004] Use relative path to stylesheet for postcss-import compat (#3435) 2024-06-05 10:02:05 -07:00
components [REF-3009] type transforming serializers (#3227) 2024-06-07 09:50:10 -07:00
experimental External assets (#3220) 2024-05-28 09:39:25 -07:00
middleware [REF-201] Separate on_load handler from initial hydration (#1847) 2023-11-30 12:21:15 -08:00
states RED-1052/rx.State as Base State (#2146) 2023-11-29 09:43:33 -08:00
utils [REF-3009] type transforming serializers (#3227) 2024-06-07 09:50:10 -07:00
__init__.py RED-1052/rx.State as Base State (#2146) 2023-11-29 09:43:33 -08:00
conftest.py [REF-201] Separate on_load handler from initial hydration (#1847) 2023-11-30 12:21:15 -08:00
test_app.py [REF-2821]Improve Dynamic Imports (#3345) 2024-05-31 16:43:10 +00:00
test_attribute_access_type.py Improved get_attribute_access_type tests (#3180) 2024-05-01 17:13:23 -07:00
test_base.py Rename pynecone to reflex (#1236) 2023-06-25 16:56:55 -07:00
test_config.py Clean up config and app API (#3197) 2024-05-02 18:15:28 -07:00
test_db_config.py Rename pynecone to reflex (#1236) 2023-06-25 16:56:55 -07:00
test_event.py Support replacing route on redirect (#3072) 2024-05-16 13:21:40 -07:00
test_model.py [REF-2658] Alembic should use batch mode for autogenerate (#3223) 2024-05-06 18:34:55 -07:00
test_prerequisites.py [REF-2676][REF-2751] Windows Skip ARM devices on bun install + Telemetry (#3212) 2024-05-06 09:50:05 -07:00
test_route.py [REF-2643] Throw Errors for duplicate Routes (#3155) 2024-05-03 12:15:40 -07:00
test_state_tree.py [REF-1988] API to Get instance of Arbitrary State class (#2678) 2024-02-27 13:02:08 -08:00
test_state.py [REF-1356] Track changes applied to Base subclass via helper method. (#2242) 2024-05-31 14:58:58 -07:00
test_style.py Allow Component.add_style to return a regular dict (#3264) 2024-05-10 20:25:04 -07:00
test_telemetry.py Catch more errors in frontend/backend (#3346) 2024-05-20 16:55:41 -07:00
test_testing.py Clean up config and app API (#3197) 2024-05-02 18:15:28 -07:00
test_var.py feat: Optionally comparing fields in Var.contains, e.g. on rx.Base based types. (#3375) 2024-05-24 17:16:26 -07:00