Commit Graph

87 Commits

Author SHA1 Message Date
Thomas Brandého
7f1aee6dc8
enable N rules for naming conventions (#4666)
* enable N rules for naming conventions

* fix pyi

* address comments

* remove unneeded code
2025-01-23 15:29:17 +01:00
Thomas Brandého
858a85a4dc
rename private fields with leading underscore in App (#4642)
* rename private fields with leading underscore in App

* fix constants API

* fix public API for some attributes of App()

* fix conflicts properly 🙈

* remove extra private

---------

Co-authored-by: Masen Furer <m_github@0x26.net>
Co-authored-by: Khaleel Al-Adhami <khaleel.aladhami@gmail.com>
2025-01-23 15:28:56 +01:00
Elijah Ahianyo
1ca36fa6c1
[ENG-1796]reflex rename- B (#4668)
* `reflex rename`- B

* add unit tests

* precommit

* dont need this comment

* move loglevel

* calm down, darglint

* add current dir to sys path
2025-01-22 15:26:12 -08:00
Thomas Brandého
4c2b2ed1c6
removing deprecated features for 0.7.0 and removing py3.9 support (#4586)
* remove deprecated features and support for py3.9

* remove other deprecated stuff

* update lock file

* fix units tests

* relock poetry

* fix _replace for computed_var

* fix some merge typo

* fix typing of deploy args

* fix benchmarks.yml versions

* console.error instead of raising Exception

* fix tests

* ignore lambdas when resolving annotations

* simplify redirect logic in event.py

* more fixes

* fix unit tests again

* give back default annotations for lambdas

* fix signature check for on_submit

* remove useless stuff

* update pyi

* readd the getattr

* raise if log_level is wrong type

* silly goose, loglevel is a subclass of str

* i don't believe this code

* add guard

---------

Co-authored-by: Khaleel Al-Adhami <khaleel.aladhami@gmail.com>
2025-01-22 11:54:37 -08:00
Khaleel Al-Adhami
bea266b8ed
make object var handle all mapping instead of just dict (#4602)
* make object var handle all mapping instead of just dict

* unbreak ci

* get it right pyright

* create generic variable for field

* add support for typeddict (to some degree)

* import from extensions
2025-01-21 13:14:02 -08:00
Thomas Brandého
9c019a65d5
check for dict passed as children for component (#4656) 2025-01-20 13:55:53 -08:00
Thomas Brandého
6e546526b4
computed var default to cache=True (#4194)
* computed var default to cache=True

* fix lifespan integration tests

* fix redis test
2025-01-16 21:49:54 +01:00
Khaleel Al-Adhami
cb24492371
fix boolean to boolen comparisons (#4620)
* fix boolean to boolen comparisons

* fixes #4618

* fix tests
2025-01-15 14:23:45 -08:00
Masen Furer
1e7a37bcf9
[ENG-4351] Add mapping for lucide icons (#4622)
* [ENG-4351] Add mapping for lucide icons

For icon names that don't auto-translate to the correct lucide tag name,
provide manual override.

Fix #4621

* account for new mapping in unit tests
2025-01-10 15:23:16 -08:00
Masen Furer
316a0c9bde
Do not allow call_function callback argument to be added afterwards (#4552)
The default behavior for EventSpec is to treat the spec as a partial, wherein
if additional unfilled arguments are available, and the event trigger wants to
pass additional arguments, they will be applied positionally.

However, it never makes sense to fill in `callback` with an event trigger arg.
Therefore, if the callback is not provided initially, set it to None explicitly
so that some invalid value cannot be added later.
2025-01-03 15:50:01 -08:00
Masen Furer
8477a1aba0
BaseState.get_var_value helper to get a value from a Var (#4553)
* BaseState.get_var_value helper to get a value from a Var

When given a state Var or a LiteralVar, retrieve the actual value associated
with the Var.

For state Vars, the returned value is directly tied to the associated state and
can be modified.

Modifying LiteralVar values or ComputedVar values will have no useful effect.

* Use Var[VAR_TYPE] annotation to take advantage of generics

This requires rx.Field to pass typing where used.

* Add case where get_var_value gets something that's not a var
2025-01-03 15:49:46 -08:00
Masen Furer
41cb2d8cff
[ENG-4083] Track internal changes in dataclass instances (#4558)
* [ENG-4083] Track internal changes in dataclass instances

Create a dynamic subclass of MutableProxy with `__dataclass_fields__` set
according to the dataclass being wrapped.

* support dataclasses.asdict on MutableProxy instances
2025-01-03 15:49:28 -08:00
Thomas Brandého
848b87070c
fix health check and skip not needed tasks (#4563) 2024-12-20 17:08:10 -08:00
Thomas Brandého
a2ec1bc1d8
add codespell to pre-commit (#4559) 2024-12-20 17:04:39 -08:00
Thomas Brandého
61cb72596e
enable PTH rule (#4476)
* enable PTH rule

* fix import in test_call_script

* fix units tests

* reorder ruff rules

* Update reflex/utils/build.py

Co-authored-by: Masen Furer <m_github@0x26.net>

* format pyproject.toml

---------

Co-authored-by: Masen Furer <m_github@0x26.net>
2024-12-13 14:06:26 -08:00
Thomas Brandého
76ce112002
add datetime var comparison operations (#4406)
* add datetime var operations

* add future annotations

* add LiteralDatetimeVar

* remove methods that don't apply

* fix serialization

* add unit and integrations test

* oops, forgot to commit that important change
2024-12-13 12:41:29 -08:00
Thomas Brandého
ff510cacc5
enable C4 rule (#4536) 2024-12-13 12:37:34 -08:00
Elijah Ahianyo
c387f517b6
[ENG-4100]Throw warnings when Redis lock is held for more than the allowed threshold (#4522)
* Throw warnings when Redis lock is held for more than the allowed threshold

* initial tests

* fix tests and address comments

* fix tests fr, and use pydantic validators

* darglint fix

* increase lock expiration in tests to 2500

* remove print statement

---------

Co-authored-by: Khaleel Al-Adhami <khaleel.aladhami@gmail.com>
2024-12-12 11:36:31 -08:00
Masen Furer
adfda8adfd
[ENG-4165] Consider default and default_factory for state vars (#4510)
* [ENG-4165] Consider default and default_factory for state vars

When determining whether a state var should be marked as optional, check that
it is missing both default and default_factory and is not required.

Fix #4471

* add test for default factory with rx.foreach (#4515)

---------

Co-authored-by: benedikt-bartscher <31854409+benedikt-bartscher@users.noreply.github.com>
2024-12-12 10:10:44 -08:00
Masen Furer
a2f14e7713
Avoid double JSON encode/decode for socket.io (#4449)
* Avoid double JSON encode/decode for socket.io

socket.io (python and js) already has a built in mechanism for JSON encoding
and decoding messages over the websocket. To use it, we pass a custom `json`
namespace which uses `format.json_dumps` (leveraging reflex serializers) to encode the
messages. This avoids sending a JSON-encoded string of JSON over the wire, and
reduces the number of serialization/deserialization passes over the message
data.

The side benefit is that debugging websocket messages in browser tools displays
the parsed JSON hierarchy and is much easier to work with.

* JSON5.parse in on_upload_progress handler responses
2024-12-12 05:47:23 -08:00
Thomas Brandého
5e026e4b27
Support python 3.13 (#4206)
* bump playwright and run tests with 3.13

* test with psycopg3

* typo

* update everything for psycopg 3.
2024-12-12 00:10:51 -08:00
Thomas Brandého
fb444ad112
add ERA rules to detect commented out code (#4472)
* add eradicate rules for commented out code

* remove output change

* fix pyi messed up indent

* fix pyi again

* fix layout docstring

* fix pyi_generator to remove commented out props from docs

* fix pyi_generator and regenerate some pyi

* fix double strip

* update all pyi

* try to fix stuff in pyi_gen

* whatever

* remove that maybe? i don't know

* fix that shit?

* fix more shit, idk

* better not see you ever again, extra line
2024-12-11 18:26:44 -08:00
benedikt-bartscher
e4b5755568
fix: handle default_factory in get_attribute_access_type (#4517)
* fix: handle default_factory in get_attribute_access_type, add tests for sqla dataclasses

* only test classes which have default_factory + add test for no default
2024-12-11 18:22:31 -08:00
benedikt-bartscher
2ee201b520
raise StateSerializationError if the state cannot be serialized (#4453)
* raise StateSerializationError if the state cannot be serialized

* fix test
2024-12-11 20:08:18 +01:00
benedikt-bartscher
3ef7106e0e
style: prefer type() over __class__ (#4512) 2024-12-10 12:35:46 -08:00
Thomas Brandého
fd0fd2c6d4
enable REFURB rules in ruff (#4466)
Co-authored-by: Masen Furer <m_github@0x26.net>
2024-12-10 09:52:03 -08:00
Thomas Brandého
4ecb0b81ce
enable RUF rules for linting (#4465) 2024-12-10 09:11:50 -08:00
Masen Furer
39cdce6960
[HOS-333] Send a "reload" message to the frontend after state expiry (#4442)
* Unit test updates

* test_client_storage: simulate backend state expiry

* [HOS-333] Send a "reload" message to the frontend after state expiry

1. a state instance expires on the backing store
2. frontend attempts to process an event against the expired token and gets a
   fresh instance of the state without router_data set
3. backend sends a "reload" message on the websocket containing the event and
   immediately stops processing
4. in response to the "reload" message, frontend sends
   [hydrate, update client storage, on_load, <previous_event>]

This allows the frontend and backend to re-syncronize on the state of the app
before continuing to process regular events.

If the event in (2) is a special hydrate event, then it is processed normally
by the middleware and the "reload" logic is skipped since this indicates an
initial load or a browser refresh.

* unit tests working with redis
2024-11-28 13:56:41 +01:00
Masen Furer
c7d3876fe6
[ENG-4137] Handle generic alias passing inspect.isclass check (#4427)
On py3.9 and py3.10, `dict[str, str]` and other typing forms are kinda
considered classes, but they still fail when doing `issubclass`, so
specifically exclude generic aliases before calling issubclass.

Fix #4424

Bonus fix: support upcasting of pydantic v1 and v2 models
2024-11-23 10:48:50 -08:00
benedikt-bartscher
a5486335a3
rx._x.asset improvements (#3624)
* wip rx._x.asset improvements

* only add symlink if it doesn't already exist

* minor improvements, add more tests

* use deprecated Generator for python3.8 support

* improve docstring

* only allow explicit shared, only validate local assets if not backend_only

* fix darglint

* allow setting backend only env to false.

* use new is_backend_only in assets

* ruffing

* Move to `rx.asset`, retain old API in `rx._x.asset`

---------

Co-authored-by: Masen Furer <m_github@0x26.net>
2024-11-21 17:16:43 -08:00
Masen Furer
a6b324bd3e
[ENG-3953] Support pydantic BaseModel (v1 and v2) as state var (#4338)
* [ENG-3953] Support pydantic BaseModel (v1 and v2) as state var

Provide serializers and mutable proxy tracking for pydantic models directly.

* conditionally define v2 serializer

Co-authored-by: Khaleel Al-Adhami <khaleel.aladhami@gmail.com>

* Add `MutableProxy._is_mutable_value` to avoid duplicate logic

* Conditionally import BaseModel to handle older pydantic v1 versions

* pre-commit fu

---------

Co-authored-by: Khaleel Al-Adhami <khaleel.aladhami@gmail.com>
2024-11-21 17:01:14 -08:00
benedikt-bartscher
e0984aa834
Allow bound method as event handler (#4348)
* subtract 1 arg if the method is a bound method

* fix it early in user_args

* only bound methods pls

* add test
2024-11-21 11:53:50 -08:00
benedikt-bartscher
1f9a17539c
fix: do not allow instantiation of State mixins (#4347)
* fix: do not allow instantiation of State mixins
Closes #4343

* improve error message for ComponentState mixins

* fix typo

Co-authored-by: Masen Furer <m_github@0x26.net>

---------

Co-authored-by: Masen Furer <m_github@0x26.net>
2024-11-18 19:15:01 -08:00
Khaleel Al-Adhami
27c1a7e94d
add typing to function vars (#4372)
* add typing to function vars

* import ParamSpec from typing_extensions

* remove ellipsis as they are not supported in 3.9

* try importing everything from extensions

* special case 3.9

* don't use Any from extensions

* get typevar from extensions
2024-11-12 20:00:02 -08:00
Masen Furer
5d88263cd8
[ENG-4098] Deconfuse key/value of State.get_value / dict / get_delta (#4371)
Because of some dodgy logic in Base.get_value and State.dict / State.get_delta
when the value of some state var X happened to be the name of another var in
the state Y, then the value for X would be returned as the value of Y.

wat.

Fixes #4369
2024-11-12 13:24:06 -08:00
Masen Furer
2b7ef0dccc
Temporarily downpin @radix-ui/themes <3.1.5 (#4370)
* Temporarily downpin @radix-ui/themes <3.1.5

A visual/style regression was introduced in @radix-ui/themes 3.1.5
as described in radix-ui/themes#627 which reflex needs to avoid.

* Get expected radix library version from component
2024-11-12 12:44:59 -08:00
Elijah Ahianyo
cd59ab5406
[ENG-4010]Codeblock cleanup in markdown (#4233)
* Codeblock cleanup in markdown

* Initial approach to getting this working with rx.memo and reflex web

* abstract the map var logic

* the tests are not valid + pyright fix

* darglint fix

* Add unit tests plus mix components

* pyi run

* rebase on main

* fix darglint

* testing different OS

* revert

* This should fix it. Right?

* Fix tests

* minor fn signature fix

* use ArgsFunctionOperation

* use destructured args and pass the tests

* fix remaining unit tests

* fix pyi files

* rebase on main

* move language regex on codeblock to markdown

* fix tests

---------

Co-authored-by: Khaleel Al-Adhami <khaleel.aladhami@gmail.com>
2024-11-07 19:18:14 -08:00
Khaleel Al-Adhami
0c482bda3c
mark var methods as private (#4319) 2024-11-07 14:50:26 -08:00
benedikt-bartscher
2cb193e8d6
improve app_src typing (#4324) 2024-11-07 14:08:37 -08:00
Khaleel Al-Adhami
b9d73edd66
add metainfo to keyevent (#4287)
* allow for event handlers to ignore args

* use a constant

* dang it darglint

* forgor

* keep the tests but move them to valid place

* add metainfo to keyevent

* format code

* fix pyi files

* generate all prefixes of event types

* change format rule
2024-11-06 15:10:02 -08:00
Thomas Brandého
4c0b49135b
stop ignoring some lint rules (#4311)
* bump python packages version

* stop ignoring some lint rules that pass ruff check

* stop ignoring rule F541

* remove sneaky test file
2024-11-06 13:32:31 -08:00
Khaleel Al-Adhami
bfa7ca639f
better missing system package message (#4306)
* better missing system package message

* change error type
2024-11-06 09:21:04 -08:00
Khaleel Al-Adhami
6334cfab0d
allow for event handlers to ignore args (#4282)
* allow for event handlers to ignore args

* use a constant

* dang it darglint

* forgor

* keep the tests but move them to valid place
2024-11-06 09:20:37 -08:00
benedikt-bartscher
4a6c16e9dc
More env var cleanup (#4248)
* fix and test bug in config env loading

* streamline env var interpretation with @adhami3310

* improve error messages, fix invalid value for TELEMETRY_ENABLED

* just a small hint

* ruffing

* fix typo from review

* refactor - ruff broke the imports..

* cleanup imports

* more

* add internal and enum env var support

* ruff cleanup

* more global imports

* revert telemetry, it lives in rx.Config

* minor fixes/cleanup

* i missed some refs

* fix darglint

* reload config is internal

* fix EnvVar name

* add test for EnvVar + minor typing improvement

* bool tests

* was this broken?

* retain old behavior

* migrate APP_HARNESS_HEADLESS to new env var system

* migrate more APP_HARNESS env vars to new config system

* migrate SCREENSHOT_DIR to new env var system

* refactor EnvVar.get to be a method

* readd deleted functions and deprecate them

* improve EnvVar api, cleanup RELOAD_CONFIG question

* move is_prod_mode back to where it was
2024-11-05 12:25:13 -08:00
Khaleel Al-Adhami
b5d1e03de1
improve object var symantics (#4290)
* improve object var symantics

* add case for serializers

* check against serializer with to = dict

* add tests

* fix typing issues

* remove default value

* older version of python doesn't have assert type

* add base to rx field cases

* get it from typing_extension
2024-11-05 09:56:10 -08:00
benedikt-bartscher
b3c199870e
bypass pydantic runtime validation for state init (#4256)
* bypass pydantic runtime validation for state init
closes #4235

* cleanup
2024-11-04 13:05:39 -08:00
Khaleel Al-Adhami
ca81e623db
add noop event (#4288)
* add noop event

* fix pyi

* get it right pyright

* why

* remove silly events

* fix tests

* remove semi colon

* errors in merging
2024-11-04 10:33:07 -08:00
Thomas Brandého
c07eb2a6a0
[ENG-3943]type check for event handler if spec arg are typed (#4046)
* type check for event handler if spec arg are typed

* fix the typecheck logic

* rearrange logic pieces

* add try except

* add try except around compare

* change form and improve type checking

* print key instead

* dang it darglint

* change wording

* add basic test to cover it

* add a slightly more complicated test

* challenge it a bit by doing small capital list

* add multiple argspec

* fix slider event order

* i hate 3.9

* add note for UnionType

* move function to types

* add a test for type hint is subclass

* make on submit dict str any

* add testing for dict cases

* add check against any

* accept dict str str

* bruh i used i twice

* escape strings and print actual error message

* disable the error and print deprecation warning instead

* disable tests

* fix doc message

---------

Co-authored-by: Khaleel Al-Adhami <khaleel.aladhami@gmail.com>
2024-10-31 12:45:28 -07:00
Elijah Ahianyo
a968231750
[ENG-3892]Shiki codeblock support decorations (#4234)
* Shiki codeblock support decorations

* add decorations to useEffect

* fix pyright

* validate decorations dict

* Fix exception message plus unit tests

* possible test fix

* fix pyright

* possible tests fix

* cast decorations before creating codeblock

* `plain` is not a valid theme

* pyi fix

* address PR comment
2024-10-31 09:33:49 +00:00
Khaleel Al-Adhami
4254eadce3
use better typing for on_load (#4274)
* use better typing for on_load

* make app dataclass

* get it right pyright

* make lifespan into a dataclass
2024-10-30 16:52:16 -07:00