Skip to content

Using Objects in Foreach ? Why is it modifying values ? #1125

Closed Answered by masenf
ml4nC3 asked this question in Q&A
Discussion options

You must be logged in to vote

Thanks for checking out pynecone and posting your code in this discussion!

I hammered on what you had and got it working, so I'll try to explain why these changes I made are necessary.

Rendering Objects

  1. dataclass-like types should inherit from pc.Base. This is a pydantic base class that allows the pynecone framework to analyze the variable types for serialization and compiled js operations.
  2. provide type annotations for all fields in a pc.Base-derived class; I added the bool annotation for is_checked.
  3. pc.Base only accepts keyword arguments, so the test_actions comprehension passes the title kwarg.
diff --git a/repro_1125/repro_1125.py b/repro_1125/repro_1125.py
index 6b3095c..013dfa4 100…

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by ml4nC3
Comment options

You must be logged in to vote
1 reply
@masenf
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants