Skip to content

Commit 60323a3

Browse files
authored
Revert fstrings change (#895)
1 parent 5674d9a commit 60323a3

File tree

7 files changed

+8
-58
lines changed

7 files changed

+8
-58
lines changed

pynecone/app.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,6 @@ def add_page(
263263
# Generate the component if it is a callable.
264264
try:
265265
component = component if isinstance(component, Component) else component()
266-
component.set_state(self.state)
267266
except TypeError as e:
268267
message = str(e)
269268
if "BaseVar" in message or "ComputedVar" in message:

pynecone/components/base/bare.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,4 @@ def create(cls, contents: Any) -> Component:
2727
return cls(contents=str(contents)) # type: ignore
2828

2929
def _render(self) -> Tag:
30-
contents = str(self.contents)
31-
if self.state is not None:
32-
check = f"{{{self.state.get_name()}"
33-
contents = str(self.contents).replace(check, f"${check}")
34-
return Tagless(contents=contents)
30+
return Tagless(contents=str(self.contents))

pynecone/components/component.py

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@
2424
from pynecone.utils import format, imports, path_ops, types
2525
from pynecone.var import BaseVar, Var
2626

27-
if typing.TYPE_CHECKING:
28-
from pynecone.state import State
29-
3027

3128
class Component(Base, ABC):
3229
"""The base class for all Pynecone components."""
@@ -37,9 +34,6 @@ class Component(Base, ABC):
3734
# The style of the component.
3835
style: Style = Style()
3936

40-
# The app state the component is connected to.
41-
state: Optional[Type[State]] = None
42-
4337
# A mapping from event triggers to event chains.
4438
event_triggers: Dict[str, Union[EventChain, Var]] = {}
4539

@@ -120,7 +114,7 @@ def __init__(self, *args, **kwargs):
120114
if types._issubclass(field_type, Var):
121115
try:
122116
# Try to create a var from the value.
123-
kwargs[key] = Var.create(value, is_string=type(value) == str)
117+
kwargs[key] = Var.create(value)
124118

125119
# Check that the var type is not None.
126120
if kwargs[key] is None:
@@ -365,7 +359,7 @@ def create(cls, *children, **props) -> Component:
365359
children = [
366360
child
367361
if isinstance(child, Component)
368-
else Bare.create(contents=Var.create(child))
362+
else Bare.create(contents=Var.create(child, is_string=True))
369363
for child in children
370364
]
371365
return cls(children=children, **props)
@@ -399,19 +393,6 @@ def add_style(self, style: ComponentStyle) -> Component:
399393
child.add_style(style)
400394
return self
401395

402-
def set_state(self, state: Type[State]):
403-
"""Set the state of the component and its children.
404-
405-
Args:
406-
state: The state to set.
407-
"""
408-
# Set the state of the component.
409-
self.state = state
410-
411-
# Set the state of the children.
412-
for child in self.children:
413-
child.set_state(state)
414-
415396
def render(self) -> str:
416397
"""Render the component.
417398

tests/components/base/__init__.py

Whitespace-only changes.

tests/components/base/test_bare.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import pytest
22

33
from pynecone.components.base.bare import Bare
4-
from pynecone.state import DefaultState
54

65

76
@pytest.mark.parametrize(
87
"contents,expected",
98
[
109
("hello", "hello"),
1110
("{}", "{}"),
12-
("{default_state.name}", "${default_state.name}"),
11+
("${default_state.name}", "${default_state.name}"),
1312
("{state.name}", "{state.name}"),
1413
],
1514
)
@@ -21,5 +20,4 @@ def test_fstrings(contents, expected):
2120
expected: The expected output.
2221
"""
2322
comp = Bare.create(contents)
24-
comp.set_state(DefaultState)
25-
assert str(comp) == f"{{`{expected}`}}"
23+
assert str(comp) == expected

tests/components/forms/test_uploads.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def test_upload_component_render(upload_component):
5353
str(upload_component) == f"<ReactDropzone multiple={{true}}{os.linesep}"
5454
"onDrop={e => File(e)}>{({getRootProps, getInputProps}) => (<Box "
5555
'sx={{"border": "1px dotted black"}}{...getRootProps()}><Input '
56-
f"type={{`file`}}{{...getInputProps()}}/>{os.linesep}"
56+
f'type="file"{{...getInputProps()}}/>{os.linesep}'
5757
f"<Button>{{`select file`}}</Button>{os.linesep}"
5858
"<Text>{`Drag and drop files here or click to select "
5959
"files`}</Text></Box>)}</ReactDropzone>"
@@ -72,7 +72,7 @@ def test_upload_component_with_props_render(upload_component_with_props):
7272
f"noDrag={{true}}{os.linesep}"
7373
"onDrop={e => File(e)}>{({getRootProps, getInputProps}) => (<Box "
7474
'sx={{"border": "1px dotted black"}}{...getRootProps()}><Input '
75-
f"type={{`file`}}{{...getInputProps()}}/>{os.linesep}"
75+
f'type="file"{{...getInputProps()}}/>{os.linesep}'
7676
f"<Button>{{`select file`}}</Button>{os.linesep}"
7777
"<Text>{`Drag and drop files here or click to select "
7878
"files`}</Text></Box>)}</ReactDropzone>"

tests/components/test_component.py

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from pynecone.components.component import Component, CustomComponent, custom_component
77
from pynecone.components.layout.box import Box
88
from pynecone.event import EVENT_ARG, EVENT_TRIGGERS, EventHandler
9-
from pynecone.state import DefaultState, State
9+
from pynecone.state import State
1010
from pynecone.style import Style
1111
from pynecone.utils import imports
1212
from pynecone.var import Var
@@ -434,27 +434,3 @@ def test_get_hooks_nested2(component3, component4):
434434
).get_hooks()
435435
== exp_hooks
436436
)
437-
438-
439-
def test_set_state(component1, component2, component3):
440-
"""Test that setting the state of a component works.
441-
442-
Args:
443-
component1: test component.
444-
component2: another component.
445-
component3: component with hooks defined.
446-
"""
447-
c2 = component2.create()
448-
c3 = component3.create()
449-
c1 = component1.create(c2, c3)
450-
451-
# State should be None by default.
452-
assert c1.state is None
453-
assert c2.state is None
454-
assert c3.state is None
455-
456-
# Setting the parent state should set the child state.
457-
c1.set_state(DefaultState)
458-
assert c1.state == DefaultState
459-
assert c2.state == DefaultState
460-
assert c3.state == DefaultState

0 commit comments

Comments
 (0)