-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle rx.State subclasses defined in function #4129
Conversation
* create a new container module: `reflex.istate.dynamic` to save references to dynamically generated substates. * for substates with `<locals>` in the name, copy these to the container module and update the name to avoid duplication. * add test for "poor man" ComponentState Fix #4128
Also use the original name when checking for the "mangled name" pattern when doing undeclared Var assignment checking.
if proposed_name not in known_names: | ||
break | ||
proposed_name = f"{cls.__name__}_{ix}" | ||
setattr(reflex.istate.dynamic, proposed_name, cls) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't this prevent garbage collection if we never clean up the refs from the container module?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the refs are for dynamically generated classes, so while it's possible that we won't clean these class objects up, i think that's okay, given that they are probably only created where needed for the app. i don't see a use case where an app creates a bunch of dynamic classes and then doesn't use them (why did it create them in the first place?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
working for me
* Handle rx.State subclasses defined in function * create a new container module: `reflex.istate.dynamic` to save references to dynamically generated substates. * for substates with `<locals>` in the name, copy these to the container module and update the name to avoid duplication. * add test for "poor man" ComponentState Fix #4128 * test_state: disable local def handling for dupe-detection test * Track the original module and name for type hint evaluation Also use the original name when checking for the "mangled name" pattern when doing undeclared Var assignment checking.
reflex.istate.dynamic
to save references to dynamically generated substates.<locals>
in the name, copy these to the container module and update the name to avoid duplication.Fix #4128