Fix f-strings in props (#891)

This commit is contained in:
Nikhil Rao 2023-04-26 21:20:40 -07:00 committed by GitHub
parent f0346506d7
commit 23a23d437c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 5 deletions

View File

@ -120,7 +120,7 @@ class Component(Base, ABC):
if types._issubclass(field_type, Var):
try:
# Try to create a var from the value.
kwargs[key] = Var.create(value)
kwargs[key] = Var.create(value, is_string=type(value) == str)
# Check that the var type is not None.
if kwargs[key] is None:
@ -365,7 +365,7 @@ class Component(Base, ABC):
children = [
child
if isinstance(child, Component)
else Bare.create(contents=Var.create(child, is_string=True))
else Bare.create(contents=Var.create(child))
for child in children
]
return cls(children=children, **props)

View File

@ -22,4 +22,4 @@ def test_fstrings(contents, expected):
"""
comp = Bare.create(contents)
comp.set_state(DefaultState)
assert str(comp) == expected
assert str(comp) == f"{{`{expected}`}}"

View File

@ -53,7 +53,7 @@ def test_upload_component_render(upload_component):
str(upload_component) == f"<ReactDropzone multiple={{true}}{os.linesep}"
"onDrop={e => File(e)}>{({getRootProps, getInputProps}) => (<Box "
'sx={{"border": "1px dotted black"}}{...getRootProps()}><Input '
f'type="file"{{...getInputProps()}}/>{os.linesep}'
f"type={{`file`}}{{...getInputProps()}}/>{os.linesep}"
f"<Button>{{`select file`}}</Button>{os.linesep}"
"<Text>{`Drag and drop files here or click to select "
"files`}</Text></Box>)}</ReactDropzone>"
@ -72,7 +72,7 @@ def test_upload_component_with_props_render(upload_component_with_props):
f"noDrag={{true}}{os.linesep}"
"onDrop={e => File(e)}>{({getRootProps, getInputProps}) => (<Box "
'sx={{"border": "1px dotted black"}}{...getRootProps()}><Input '
f'type="file"{{...getInputProps()}}/>{os.linesep}'
f"type={{`file`}}{{...getInputProps()}}/>{os.linesep}"
f"<Button>{{`select file`}}</Button>{os.linesep}"
"<Text>{`Drag and drop files here or click to select "
"files`}</Text></Box>)}</ReactDropzone>"