Skip to content

Commit 20cf393

Browse files
author
Shammamah Hossain
committed
Move logic for determining default value into create_prop_docstring.
1 parent 37043d8 commit 20cf393

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

dash/development/_py_components_generation.py

+12-9
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ def create_docstring(component_name, props, description):
251251
else prop['flowType'],
252252
required=prop['required'],
253253
description=prop['description'],
254-
default=prop.get('defaultValue', {'value': ''})['value'],
254+
default=prop.get('defaultValue'),
255255
indent_num=0,
256256
is_flow_type='flowType' in prop and 'type' not in prop)
257257
for p, prop in list(filter_props(props).items())))
@@ -410,8 +410,10 @@ def create_prop_docstring(prop_name, type_object, required, description,
410410
Component is required?
411411
description: str
412412
Dash component description
413-
default: str
414-
Default value for prop
413+
default: dict
414+
Either None if a default value is not defined, or
415+
dict containing the key 'value' that defines a
416+
default value for the prop
415417
indent_num: int
416418
Number of indents to use for the context block
417419
(creates 2 spaces for every indent)
@@ -429,6 +431,11 @@ def create_prop_docstring(prop_name, type_object, required, description,
429431
indent_num=indent_num + 1)
430432
indent_spacing = ' ' * indent_num
431433

434+
if default is None:
435+
default = ''
436+
else:
437+
default = default['value']
438+
432439
is_required = 'optional'
433440
if required:
434441
is_required = 'required'
@@ -473,9 +480,7 @@ def shape_or_exact():
473480
type_object=prop,
474481
required=prop['required'],
475482
description=prop.get('description', ''),
476-
default=prop.get(
477-
'defaultValue', {'value': ''}
478-
)['value'],
483+
default=prop.get('defaultValue'),
479484
indent_num=1
480485
) for prop_name, prop in
481486
list(type_object['value'].items())))
@@ -571,9 +576,7 @@ def map_js_to_py_types_flow_types(type_object):
571576
type_object=prop['value'],
572577
required=prop['value']['required'],
573578
description=prop['value'].get('description', ''),
574-
default=prop.get(
575-
'defaultValue', {'value': ''}
576-
)['value'],
579+
default=prop.get('defaultValue'),
577580
indent_num=indent_num,
578581
is_flow_type=True)
579582
for prop in type_object['signature']['properties']))),

0 commit comments

Comments
 (0)