Skip to content

Commit d5b0ebe

Browse files
committed
Add Optional to every prop
1 parent 8734e1b commit d5b0ebe

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

dash/development/_py_components_generation.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ def __init__(
102102
prop_keys = list(props.keys())
103103
if "children" in props and "children" in list_of_valid_keys:
104104
prop_keys.remove("children")
105-
default_argtext = (
106-
f"children: {get_prop_typing('node', '', '', {})} = None,\n "
107-
)
105+
# TODO For dash 3.0, remove the Optional and = None for proper typing.
106+
# Also add the other required props after children.
107+
default_argtext = f"children: typing.Optional[{get_prop_typing('node', '', '', {})}] = None,\n "
108108
args = "{k: _locals[k] for k in _explicit_args if k != 'children'}"
109109
argtext = "children=children, **args"
110110
else:
@@ -138,21 +138,19 @@ def __init__(
138138
or prop_key == "setProps"
139139
):
140140
continue
141-
required = prop.get("required")
142-
type_info = prop.get("type")
143141

144-
default_value = "Component.REQUIRED" if required else "Component.UNDEFINED"
142+
type_info = prop.get("type")
145143

146144
if not type_info:
147145
print(f"Invalid prop type for typing: {prop_key}")
148-
default_arglist.append(f"{prop_key} = {default_value}")
146+
default_arglist.append(f"{prop_key} = None")
149147
continue
150148

151149
type_name = type_info.get("name")
152150

153151
typed = get_prop_typing(type_name, typename, prop_key, type_info, namespace)
154152

155-
arg_value = f"{prop_key}: {typed} = {default_value}"
153+
arg_value = f"{prop_key}: typing.Optional[{typed}] = None"
156154

157155
default_arglist.append(arg_value)
158156

0 commit comments

Comments
 (0)