From 7e96e57a6727dfa2ffc682db4d75ae445c1dc9cb Mon Sep 17 00:00:00 2001 From: Shammamah Hossain Date: Wed, 19 Jun 2019 13:22:38 -0400 Subject: [PATCH 01/19] Change 'A' to 'An' for component names that begin with vowels. --- dash/development/_py_components_generation.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dash/development/_py_components_generation.py b/dash/development/_py_components_generation.py index 66db6a12d6..70cbd0f542 100644 --- a/dash/development/_py_components_generation.py +++ b/dash/development/_py_components_generation.py @@ -236,10 +236,11 @@ def create_docstring(component_name, props, description): props = reorder_props(props=props) return ( - """A {name} component.\n{description} + """A{n} {name} component.\n{description} Keyword arguments:\n{args}""" ).format( + n='n' if component_name[0].lower() in ['a', 'e', 'i', 'o', 'u'] else '', name=component_name, description=description, args='\n'.join( From cf13ccb3e4f36150ce545ed836c0e92e0a82893e Mon Sep 17 00:00:00 2001 From: Shammamah Hossain Date: Wed, 19 Jun 2019 13:23:09 -0400 Subject: [PATCH 02/19] Add support for adding default values to the end of the docstring. --- dash/development/_py_components_generation.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/dash/development/_py_components_generation.py b/dash/development/_py_components_generation.py index 70cbd0f542..b8db519da4 100644 --- a/dash/development/_py_components_generation.py +++ b/dash/development/_py_components_generation.py @@ -250,6 +250,7 @@ def create_docstring(component_name, props, description): else prop['flowType'], required=prop['required'], description=prop['description'], + default=prop['defaultValue']['value'] if 'defaultValue' in prop.keys() else '', indent_num=0, is_flow_type='flowType' in prop and 'type' not in prop) for p, prop in list(filter_props(props).items()))) @@ -394,7 +395,7 @@ def filter_props(props): # pylint: disable=too-many-arguments def create_prop_docstring(prop_name, type_object, required, description, - indent_num, is_flow_type=False): + default, indent_num, is_flow_type=False): """ Create the Dash component prop docstring @@ -423,24 +424,25 @@ def create_prop_docstring(prop_name, type_object, required, description, type_object=type_object, is_flow_type=is_flow_type, indent_num=indent_num + 1) - indent_spacing = ' ' * indent_num if '\n' in py_type_name: return '{indent_spacing}- {name} ({is_required}): {description}. ' \ - '{name} has the following type: {type}'.format( + '{name} has the following type: {type}{defaultValue})'.format( indent_spacing=indent_spacing, name=prop_name, type=py_type_name, description=description, + defaultValue=' (Default: {})'.format(default) if len(default) > 0 else '', is_required='required' if required else 'optional') return '{indent_spacing}- {name} ({type}' \ - '{is_required}){description}'.format( + '{is_required}){description}{defaultValue}'.format( indent_spacing=indent_spacing, name=prop_name, type='{}; '.format(py_type_name) if py_type_name else '', description=( ': {}'.format(description) if description != '' else '' ), + defaultValue=' (Default: {})'.format(default) if len(default) > 0 else '', is_required='required' if required else 'optional') @@ -459,6 +461,7 @@ def shape_or_exact(): type_object=prop, required=prop['required'], description=prop.get('description', ''), + default=prop['defaultValue']['value'] if 'defaultValue' in prop.keys() else '', indent_num=1 ) for prop_name, prop in list(type_object['value'].items()))) From ec642f1c9d34ca29c018ff1fa4aab767354f6a8a Mon Sep 17 00:00:00 2001 From: Shammamah Hossain Date: Wed, 19 Jun 2019 14:03:07 -0400 Subject: [PATCH 03/19] Handle periods for nested props, and clean up default value logic. --- dash/development/_py_components_generation.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/dash/development/_py_components_generation.py b/dash/development/_py_components_generation.py index b8db519da4..6e27280d0d 100644 --- a/dash/development/_py_components_generation.py +++ b/dash/development/_py_components_generation.py @@ -425,14 +425,19 @@ def create_prop_docstring(prop_name, type_object, required, description, is_flow_type=is_flow_type, indent_num=indent_num + 1) indent_spacing = ' ' * indent_num + default_string = ' (Default: {})'.format(default) if len(default) > 0 \ + and 'null' not in str(default) \ + and '[]' not in str(default) else '' + if '\n' in py_type_name: - return '{indent_spacing}- {name} ({is_required}): {description}. ' \ - '{name} has the following type: {type}{defaultValue})'.format( + return '{indent_spacing}- {name} ({is_required}): {description}{period} ' \ + '{name} has the following type: {type}{defaultValue}'.format( indent_spacing=indent_spacing, name=prop_name, type=py_type_name, description=description, - defaultValue=' (Default: {})'.format(default) if len(default) > 0 else '', + period='.' if len(description) > 0 and description[-1] != '.' else '', + defaultValue='\n' + indent_spacing + default_string.replace('\n', '\n' + indent_spacing), is_required='required' if required else 'optional') return '{indent_spacing}- {name} ({type}' \ '{is_required}){description}{defaultValue}'.format( @@ -442,7 +447,7 @@ def create_prop_docstring(prop_name, type_object, required, description, description=( ': {}'.format(description) if description != '' else '' ), - defaultValue=' (Default: {})'.format(default) if len(default) > 0 else '', + defaultValue=default_string, is_required='required' if required else 'optional') From 31fe48f56b405488bea05b5e78e0e4e254898e70 Mon Sep 17 00:00:00 2001 From: Shammamah Hossain Date: Wed, 19 Jun 2019 17:38:51 -0400 Subject: [PATCH 04/19] Put default values next to the type definition in docstring. --- dash/development/_py_components_generation.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/dash/development/_py_components_generation.py b/dash/development/_py_components_generation.py index 6e27280d0d..332572cb88 100644 --- a/dash/development/_py_components_generation.py +++ b/dash/development/_py_components_generation.py @@ -425,30 +425,31 @@ def create_prop_docstring(prop_name, type_object, required, description, is_flow_type=is_flow_type, indent_num=indent_num + 1) indent_spacing = ' ' * indent_num - default_string = ' (Default: {})'.format(default) if len(default) > 0 \ - and 'null' not in str(default) \ - and '[]' not in str(default) else '' + + is_required = 'optional' + if required: + is_required = 'required' + elif len(default) > 0 and 'null' not in str(default) and '[]' not in str(default): + is_required = 'default {}'.format(default.replace('\n', '\n' + indent_spacing)) if '\n' in py_type_name: return '{indent_spacing}- {name} ({is_required}): {description}{period} ' \ - '{name} has the following type: {type}{defaultValue}'.format( + '{name} has the following type: {type}'.format( indent_spacing=indent_spacing, name=prop_name, type=py_type_name, description=description, period='.' if len(description) > 0 and description[-1] != '.' else '', - defaultValue='\n' + indent_spacing + default_string.replace('\n', '\n' + indent_spacing), - is_required='required' if required else 'optional') + is_required=is_required) return '{indent_spacing}- {name} ({type}' \ - '{is_required}){description}{defaultValue}'.format( + '{is_required}){description}'.format( indent_spacing=indent_spacing, name=prop_name, type='{}; '.format(py_type_name) if py_type_name else '', description=( ': {}'.format(description) if description != '' else '' ), - defaultValue=default_string, - is_required='required' if required else 'optional') + is_required=is_required) def map_js_to_py_types_prop_types(type_object): From 31210a71bb56107f1233b9cc6953f80f5a89ccf4 Mon Sep 17 00:00:00 2001 From: Shammamah Hossain Date: Thu, 20 Jun 2019 14:47:43 -0400 Subject: [PATCH 05/19] Add prop type specification for nested props (PropTypes.shape). --- dash/development/_py_components_generation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dash/development/_py_components_generation.py b/dash/development/_py_components_generation.py index 332572cb88..cc9dcd4280 100644 --- a/dash/development/_py_components_generation.py +++ b/dash/development/_py_components_generation.py @@ -433,7 +433,7 @@ def create_prop_docstring(prop_name, type_object, required, description, is_required = 'default {}'.format(default.replace('\n', '\n' + indent_spacing)) if '\n' in py_type_name: - return '{indent_spacing}- {name} ({is_required}): {description}{period} ' \ + return '{indent_spacing}- {name} (dict; {is_required}): {description}{period} ' \ '{name} has the following type: {type}'.format( indent_spacing=indent_spacing, name=prop_name, From 6ae9004dfaece1f8308d3537de08647e07b32309 Mon Sep 17 00:00:00 2001 From: Shammamah Hossain Date: Thu, 20 Jun 2019 16:01:33 -0400 Subject: [PATCH 06/19] Fix pylint errors. Remove string comparison to number. --- dash/development/_py_components_generation.py | 52 +++++++++++-------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/dash/development/_py_components_generation.py b/dash/development/_py_components_generation.py index 37526e89ae..3007352a19 100644 --- a/dash/development/_py_components_generation.py +++ b/dash/development/_py_components_generation.py @@ -240,7 +240,8 @@ def create_docstring(component_name, props, description): Keyword arguments:\n{args}""" ).format( - n='n' if component_name[0].lower() in ['a', 'e', 'i', 'o', 'u'] else '', + n='n' if component_name[0].lower() in ['a', 'e', 'i', 'o', 'u'] + else '', name=component_name, description=description, args='\n'.join( @@ -250,7 +251,8 @@ def create_docstring(component_name, props, description): else prop['flowType'], required=prop['required'], description=prop['description'], - default=prop['defaultValue']['value'] if 'defaultValue' in prop.keys() else '', + default=prop['defaultValue']['value'] + if 'defaultValue' in prop.keys() else '', indent_num=0, is_flow_type='flowType' in prop and 'type' not in prop) for p, prop in list(filter_props(props).items()))) @@ -429,27 +431,30 @@ def create_prop_docstring(prop_name, type_object, required, description, is_required = 'optional' if required: is_required = 'required' - elif len(default) > 0 and 'null' not in str(default) and '[]' not in str(default): - is_required = 'default {}'.format(default.replace('\n', '\n' + indent_spacing)) + elif default and 'null' not in str(default) and '[]' not in str(default): + is_required = 'default {}'.format( + default.replace('\n', '\n' + indent_spacing) + ) if '\n' in py_type_name: - return '{indent_spacing}- {name} (dict; {is_required}): {description}{period} ' \ - '{name} has the following type: {type}'.format( - indent_spacing=indent_spacing, - name=prop_name, - type=py_type_name, - description=description, - period='.' if len(description) > 0 and description[-1] != '.' else '', - is_required=is_required) + return '{indent_spacing}- {name} (dict; {is_required}): ' \ + '{description}{period} ' \ + '{name} has the following type: {type}'.format( + indent_spacing=indent_spacing, + name=prop_name, + type=py_type_name, + description=description, + period='.' if description and description[-1] != '.' else '', + is_required=is_required) return '{indent_spacing}- {name} ({type}' \ - '{is_required}){description}'.format( - indent_spacing=indent_spacing, - name=prop_name, - type='{}; '.format(py_type_name) if py_type_name else '', - description=( - ': {}'.format(description) if description != '' else '' - ), - is_required=is_required) + '{is_required}){description}'.format( + indent_spacing=indent_spacing, + name=prop_name, + type='{}; '.format(py_type_name) if py_type_name else '', + description=( + ': {}'.format(description) if description != '' else '' + ), + is_required=is_required) def map_js_to_py_types_prop_types(type_object): @@ -467,7 +472,8 @@ def shape_or_exact(): type_object=prop, required=prop['required'], description=prop.get('description', ''), - default=prop['defaultValue']['value'] if 'defaultValue' in prop.keys() else '', + default=prop['defaultValue']['value'] + if 'defaultValue' in prop.keys() else '', indent_num=1 ) for prop_name, prop in list(type_object['value'].items()))) @@ -558,6 +564,8 @@ def map_js_to_py_types_flow_types(type_object): type_object=prop['value'], required=prop['value']['required'], description=prop['value'].get('description', ''), + default=prop['defaultValue']['value'] + if 'defaultValue' in prop.keys() else '', indent_num=indent_num, is_flow_type=True) for prop in type_object['signature']['properties']))), @@ -590,7 +598,7 @@ def js_to_py_type(type_object, is_flow_type=False, indent_num=0): if 'computed' in type_object and type_object['computed'] \ or type_object.get('type', '') == 'function': return '' - elif js_type_name in js_to_py_types: + if js_type_name in js_to_py_types: if js_type_name == 'signature': # This is a Flow object w/ signature return js_to_py_types[js_type_name](indent_num) # All other types From cc2253aea3a22e75b68b6d4cdd51cdbaac09b528 Mon Sep 17 00:00:00 2001 From: Shammamah Hossain Date: Thu, 20 Jun 2019 17:35:35 -0400 Subject: [PATCH 07/19] Add 'dict' to all props that are objects. Add 'dict' to all props that are objects in metadata_test. --- tests/unit/development/metadata_test.py | 8 ++++---- tests/unit/development/test_base_component.py | 20 +++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/unit/development/metadata_test.py b/tests/unit/development/metadata_test.py index edb6712634..e58b9697e3 100644 --- a/tests/unit/development/metadata_test.py +++ b/tests/unit/development/metadata_test.py @@ -21,19 +21,19 @@ class Table(Component): - optionalUnion (string | number; optional) - optionalArrayOf (list of numbers; optional) - optionalObjectOf (dict with strings as keys and values of type number; optional) -- optionalObjectWithExactAndNestedDescription (optional): . optionalObjectWithExactAndNestedDescription has the following type: dict containing keys 'color', 'fontSize', 'figure'. +- optionalObjectWithExactAndNestedDescription (dict; optional): optionalObjectWithExactAndNestedDescription has the following type: dict containing keys 'color', 'fontSize', 'figure'. Those keys have the following types: - color (string; optional) - fontSize (number; optional) - - figure (optional): Figure is a plotly graph object. figure has the following type: dict containing keys 'data', 'layout'. + - figure (dict; optional): Figure is a plotly graph object. figure has the following type: dict containing keys 'data', 'layout'. Those keys have the following types: - data (list of dicts; optional): data is a collection of traces - layout (dict; optional): layout describes the rest of the figure -- optionalObjectWithShapeAndNestedDescription (optional): . optionalObjectWithShapeAndNestedDescription has the following type: dict containing keys 'color', 'fontSize', 'figure'. +- optionalObjectWithShapeAndNestedDescription (dict; optional): optionalObjectWithShapeAndNestedDescription has the following type: dict containing keys 'color', 'fontSize', 'figure'. Those keys have the following types: - color (string; optional) - fontSize (number; optional) - - figure (optional): Figure is a plotly graph object. figure has the following type: dict containing keys 'data', 'layout'. + - figure (dict; optional): Figure is a plotly graph object. figure has the following type: dict containing keys 'data', 'layout'. Those keys have the following types: - data (list of dicts; optional): data is a collection of traces - layout (dict; optional): layout describes the rest of the figure diff --git a/tests/unit/development/test_base_component.py b/tests/unit/development/test_base_component.py index 51d94fe0e5..b962fb285d 100644 --- a/tests/unit/development/test_base_component.py +++ b/tests/unit/development/test_base_component.py @@ -815,7 +815,7 @@ def setUp(self): "Those keys have the following types:", " - color (string; optional)", " - fontSize (number; optional)", - " - figure (optional): Figure is a plotly graph object. figure has the following type: dict containing keys 'data', 'layout'.", # noqa: E501 + " - figure (dict; optional): Figure is a plotly graph object. figure has the following type: dict containing keys 'data', 'layout'.", # noqa: E501 "Those keys have the following types:", " - data (list of dicts; optional): data is a collection of traces", " - layout (dict; optional): layout describes the rest of the figure" # noqa: E501 @@ -828,7 +828,7 @@ def setUp(self): "Those keys have the following types:", " - color (string; optional)", " - fontSize (number; optional)", - " - figure (optional): Figure is a plotly graph object. figure has the following type: dict containing keys 'data', 'layout'.", # noqa: E501 + " - figure (dict; optional): Figure is a plotly graph object. figure has the following type: dict containing keys 'data', 'layout'.", # noqa: E501 "Those keys have the following types:", " - data (list of dicts; optional): data is a collection of traces", " - layout (dict; optional): layout describes the rest of the figure" # noqa: E501 @@ -896,7 +896,7 @@ def assert_docstring(assertEqual, docstring): "- optionalObjectOf (dict with strings as keys and values " "of type number; optional)", - "- optionalObjectWithExactAndNestedDescription (optional): . " + "- optionalObjectWithExactAndNestedDescription (dict; optional): " "optionalObjectWithExactAndNestedDescription has the " "following type: dict containing keys " "'color', 'fontSize', 'figure'.", @@ -905,7 +905,7 @@ def assert_docstring(assertEqual, docstring): " - color (string; optional)", " - fontSize (number; optional)", - " - figure (optional): Figure is a plotly graph object. " + " - figure (dict; optional): Figure is a plotly graph object. " "figure has the following type: dict containing " "keys 'data', 'layout'.", @@ -915,7 +915,7 @@ def assert_docstring(assertEqual, docstring): " - layout (dict; optional): layout describes " "the rest of the figure", - "- optionalObjectWithShapeAndNestedDescription (optional): . " + "- optionalObjectWithShapeAndNestedDescription (dict; optional): " "optionalObjectWithShapeAndNestedDescription has the " "following type: dict containing keys " "'color', 'fontSize', 'figure'.", @@ -924,7 +924,7 @@ def assert_docstring(assertEqual, docstring): " - color (string; optional)", " - fontSize (number; optional)", - " - figure (optional): Figure is a plotly graph object. " + " - figure (dict; optional): Figure is a plotly graph object. " "figure has the following type: dict containing " "keys 'data', 'layout'.", @@ -995,7 +995,7 @@ def setUp(self): "dict containing keys 'customData', 'value'.", "Those keys have the following types:", - "- customData (required): . customData has the following type: dict containing keys 'checked', 'children', 'customData', 'disabled', 'label', 'primaryText', 'secondaryText', 'style', 'value'.", + "- customData (dict; required): customData has the following type: dict containing keys 'checked', 'children', 'customData', 'disabled', 'label', 'primaryText', 'secondaryText', 'style', 'value'.", " Those keys have the following types:", " - checked (boolean; optional)", " - children (a list of or a singular dash component, string or number; optional)", @@ -1052,7 +1052,7 @@ def assert_flow_docstring(assertEqual, docstring): "- requiredUnion (string | number; required)", - "- optionalSignature(shape) (optional): This is a test of an object's shape. " + "- optionalSignature(shape) (dict; optional): This is a test of an object's shape. " "optionalSignature(shape) has the following type: dict containing keys 'checked', " "'children', 'customData', 'disabled', 'label', 'primaryText', 'secondaryText', " "'style', 'value'.", @@ -1068,12 +1068,12 @@ def assert_flow_docstring(assertEqual, docstring): " - style (dict; optional)", " - value (bool | number | str | dict | list; required)", - "- requiredNested (required): . requiredNested has the following type: dict containing " + "- requiredNested (dict; required): requiredNested has the following type: dict containing " "keys 'customData', 'value'.", " Those keys have the following types:", - " - customData (required): . customData has the following type: dict containing " + " - customData (dict; required): customData has the following type: dict containing " "keys 'checked', 'children', 'customData', 'disabled', 'label', 'primaryText', " "'secondaryText', 'style', 'value'.", From 60809ab3062c98454d941d9cdb7ccaa2e2958cd7 Mon Sep 17 00:00:00 2001 From: Shammamah Hossain Date: Thu, 20 Jun 2019 17:38:31 -0400 Subject: [PATCH 08/19] Replace 'optional' with default values for props that have them specified. Replace 'optional' with default values for props that have them specified in metadata_test. --- tests/unit/development/metadata_test.py | 4 ++-- tests/unit/development/test_base_component.py | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/unit/development/metadata_test.py b/tests/unit/development/metadata_test.py index e58b9697e3..6505a41448 100644 --- a/tests/unit/development/metadata_test.py +++ b/tests/unit/development/metadata_test.py @@ -12,9 +12,9 @@ class Table(Component): - children (a list of or a singular dash component, string or number; optional) - optionalArray (list; optional): Description of optionalArray - optionalBool (boolean; optional) -- optionalNumber (number; optional) +- optionalNumber (number; default 42) - optionalObject (dict; optional) -- optionalString (string; optional) +- optionalString (string; default 'hello world') - optionalNode (a list of or a singular dash component, string or number; optional) - optionalElement (dash component; optional) - optionalEnum (a value equal to: 'News', 'Photos'; optional) diff --git a/tests/unit/development/test_base_component.py b/tests/unit/development/test_base_component.py index b962fb285d..c39fe9a766 100644 --- a/tests/unit/development/test_base_component.py +++ b/tests/unit/development/test_base_component.py @@ -881,9 +881,9 @@ def assert_docstring(assertEqual, docstring): "- children (a list of or a singular dash component, string or number; optional)", # noqa: E501 "- optionalArray (list; optional): Description of optionalArray", "- optionalBool (boolean; optional)", - "- optionalNumber (number; optional)", + "- optionalNumber (number; default 42)", "- optionalObject (dict; optional)", - "- optionalString (string; optional)", + "- optionalString (string; default 'hello world')", "- optionalNode (a list of or a singular dash component, " "string or number; optional)", @@ -1040,8 +1040,8 @@ def assert_flow_docstring(assertEqual, docstring): "", "Keyword arguments:", "- requiredString (string; required): A required string", - "- optionalString (string; optional): A string that isn't required.", - "- optionalBoolean (boolean; optional): A boolean test", + "- optionalString (string; default ''): A string that isn't required.", + "- optionalBoolean (boolean; default false): A boolean test", "- optionalNode (a list of or a singular dash component, string or number; optional): " "A node test", From 77754e17af6410ce12429aaddc8a3f28677d8cea Mon Sep 17 00:00:00 2001 From: Shammamah Hossain Date: Thu, 20 Jun 2019 17:42:13 -0400 Subject: [PATCH 09/19] Add more logic to adding period to the end of descriptions in docstrings. Fix pylint errors. --- dash/development/_py_components_generation.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/dash/development/_py_components_generation.py b/dash/development/_py_components_generation.py index 3007352a19..d928aa3f5b 100644 --- a/dash/development/_py_components_generation.py +++ b/dash/development/_py_components_generation.py @@ -438,13 +438,14 @@ def create_prop_docstring(prop_name, type_object, required, description, if '\n' in py_type_name: return '{indent_spacing}- {name} (dict; {is_required}): ' \ - '{description}{period} ' \ + '{description}{period}' \ '{name} has the following type: {type}'.format( indent_spacing=indent_spacing, name=prop_name, type=py_type_name, description=description, - period='.' if description and description[-1] != '.' else '', + period='. ' if description.strip() + and description.strip()[-1] != '.' else '', is_required=is_required) return '{indent_spacing}- {name} ({type}' \ '{is_required}){description}'.format( From db2230be72954ced4f3f54f71878c90ae3b4fa8f Mon Sep 17 00:00:00 2001 From: Shammamah Hossain Date: Thu, 20 Jun 2019 17:42:33 -0400 Subject: [PATCH 10/19] Remove unnecessary comma. --- dash/development/_py_components_generation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dash/development/_py_components_generation.py b/dash/development/_py_components_generation.py index d928aa3f5b..39317e33b1 100644 --- a/dash/development/_py_components_generation.py +++ b/dash/development/_py_components_generation.py @@ -521,7 +521,7 @@ def shape_or_exact(): # React's PropTypes.shape shape=shape_or_exact, # React's PropTypes.exact - exact=shape_or_exact, + exact=shape_or_exact ) From 9271f5b53ab073e15d097de2a5ecbd43883a02fe Mon Sep 17 00:00:00 2001 From: Shammamah Hossain Date: Fri, 21 Jun 2019 10:03:04 -0400 Subject: [PATCH 11/19] Remove '.keys()' when searching prop dictionary. --- dash/development/_py_components_generation.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dash/development/_py_components_generation.py b/dash/development/_py_components_generation.py index 39317e33b1..c11db6597f 100644 --- a/dash/development/_py_components_generation.py +++ b/dash/development/_py_components_generation.py @@ -252,7 +252,7 @@ def create_docstring(component_name, props, description): required=prop['required'], description=prop['description'], default=prop['defaultValue']['value'] - if 'defaultValue' in prop.keys() else '', + if 'defaultValue' in prop else '', indent_num=0, is_flow_type='flowType' in prop and 'type' not in prop) for p, prop in list(filter_props(props).items()))) @@ -474,7 +474,7 @@ def shape_or_exact(): required=prop['required'], description=prop.get('description', ''), default=prop['defaultValue']['value'] - if 'defaultValue' in prop.keys() else '', + if 'defaultValue' in prop else '', indent_num=1 ) for prop_name, prop in list(type_object['value'].items()))) @@ -566,7 +566,7 @@ def map_js_to_py_types_flow_types(type_object): required=prop['value']['required'], description=prop['value'].get('description', ''), default=prop['defaultValue']['value'] - if 'defaultValue' in prop.keys() else '', + if 'defaultValue' in prop else '', indent_num=indent_num, is_flow_type=True) for prop in type_object['signature']['properties']))), From f5bbab4d2bf73e159a3bd96321c59480fd21d134 Mon Sep 17 00:00:00 2001 From: Shammamah Hossain Date: Fri, 21 Jun 2019 10:03:47 -0400 Subject: [PATCH 12/19] Remove unnecessary '.keys()'. --- dash/development/_py_components_generation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dash/development/_py_components_generation.py b/dash/development/_py_components_generation.py index c11db6597f..09349aea7b 100644 --- a/dash/development/_py_components_generation.py +++ b/dash/development/_py_components_generation.py @@ -293,7 +293,7 @@ def parse_wildcards(props): """ list_of_valid_wildcard_attr_prefixes = [] for wildcard_attr in ["data-*", "aria-*"]: - if wildcard_attr in props.keys(): + if wildcard_attr in props: list_of_valid_wildcard_attr_prefixes.append(wildcard_attr[:-1]) return list_of_valid_wildcard_attr_prefixes From 7c6d72b22b7e52d5645823d8b62a62f67fc253a6 Mon Sep 17 00:00:00 2001 From: Shammamah Hossain Date: Fri, 21 Jun 2019 10:04:30 -0400 Subject: [PATCH 13/19] Add 'default' to docstring. --- dash/development/_py_components_generation.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dash/development/_py_components_generation.py b/dash/development/_py_components_generation.py index 09349aea7b..bbe7ad7ae9 100644 --- a/dash/development/_py_components_generation.py +++ b/dash/development/_py_components_generation.py @@ -411,6 +411,8 @@ def create_prop_docstring(prop_name, type_object, required, description, Component is required? description: str Dash component description + default: str + Default value for prop indent_num: int Number of indents to use for the context block (creates 2 spaces for every indent) From c70659e1939d67df4f067839115ca96f5d3035c6 Mon Sep 17 00:00:00 2001 From: Shammamah Hossain Date: Fri, 21 Jun 2019 10:05:44 -0400 Subject: [PATCH 14/19] Check whether default values equal null/empty types instead of whether they contain them. --- dash/development/_py_components_generation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dash/development/_py_components_generation.py b/dash/development/_py_components_generation.py index bbe7ad7ae9..a88aa5787b 100644 --- a/dash/development/_py_components_generation.py +++ b/dash/development/_py_components_generation.py @@ -433,7 +433,7 @@ def create_prop_docstring(prop_name, type_object, required, description, is_required = 'optional' if required: is_required = 'required' - elif default and 'null' not in str(default) and '[]' not in str(default): + elif default and default not in ['null', '{}', '[]']: is_required = 'default {}'.format( default.replace('\n', '\n' + indent_spacing) ) From bbccf473f11b6e0da760f194f4ce2928814a587f Mon Sep 17 00:00:00 2001 From: Shammamah Hossain Date: Fri, 21 Jun 2019 10:18:50 -0400 Subject: [PATCH 15/19] Make default value logic shorter. --- dash/development/_py_components_generation.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/dash/development/_py_components_generation.py b/dash/development/_py_components_generation.py index a88aa5787b..fc9b1900b2 100644 --- a/dash/development/_py_components_generation.py +++ b/dash/development/_py_components_generation.py @@ -251,8 +251,7 @@ def create_docstring(component_name, props, description): else prop['flowType'], required=prop['required'], description=prop['description'], - default=prop['defaultValue']['value'] - if 'defaultValue' in prop else '', + default=prop.get('defaultValue', {'value': ''})['value'], indent_num=0, is_flow_type='flowType' in prop and 'type' not in prop) for p, prop in list(filter_props(props).items()))) @@ -475,8 +474,9 @@ def shape_or_exact(): type_object=prop, required=prop['required'], description=prop.get('description', ''), - default=prop['defaultValue']['value'] - if 'defaultValue' in prop else '', + default=prop.get( + 'defaultValue', {'value': ''} + )['value'], indent_num=1 ) for prop_name, prop in list(type_object['value'].items()))) @@ -567,8 +567,9 @@ def map_js_to_py_types_flow_types(type_object): type_object=prop['value'], required=prop['value']['required'], description=prop['value'].get('description', ''), - default=prop['defaultValue']['value'] - if 'defaultValue' in prop else '', + default=prop.get( + 'defaultValue', {'value': ''} + )['value'], indent_num=indent_num, is_flow_type=True) for prop in type_object['signature']['properties']))), From 56d984d3119a7837b28bf1e30b6a57b0e2a184c6 Mon Sep 17 00:00:00 2001 From: Shammamah Hossain Date: Fri, 21 Jun 2019 15:08:28 -0400 Subject: [PATCH 16/19] Add more logic for 'list of' types. Only add 's' to end if referring to a non-dict type; otherwise, change 'dict' to 'dicts' and don't put an 's' on the end. Fix pylint error. --- dash/development/_py_components_generation.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/dash/development/_py_components_generation.py b/dash/development/_py_components_generation.py index fc9b1900b2..b1bb3628ce 100644 --- a/dash/development/_py_components_generation.py +++ b/dash/development/_py_components_generation.py @@ -508,8 +508,13 @@ def shape_or_exact(): # React's PropTypes.arrayOf arrayOf=lambda: ( - "list" + ((" of {}s").format( - js_to_py_type(type_object["value"])) + "list" + ((" of {}").format( + js_to_py_type(type_object["value"]) + 's' + if js_to_py_type(type_object["value"]).split(' ')[0] != 'dict' + else js_to_py_type(type_object["value"]).replace( + 'dict', 'dicts', 1 + ) + ) if js_to_py_type(type_object["value"]) != "" else "") ), From 37043d85e0e082e5964882b996d69c05ab3c0474 Mon Sep 17 00:00:00 2001 From: Shammamah Hossain Date: Fri, 21 Jun 2019 15:10:04 -0400 Subject: [PATCH 17/19] Simplify logic for adding periods onto ends of descriptions. Remove all periods from the end of description, if there are any, and add in another one. --- dash/development/_py_components_generation.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/dash/development/_py_components_generation.py b/dash/development/_py_components_generation.py index b1bb3628ce..e226136e0d 100644 --- a/dash/development/_py_components_generation.py +++ b/dash/development/_py_components_generation.py @@ -444,9 +444,8 @@ def create_prop_docstring(prop_name, type_object, required, description, indent_spacing=indent_spacing, name=prop_name, type=py_type_name, - description=description, - period='. ' if description.strip() - and description.strip()[-1] != '.' else '', + description=description.strip().strip('.'), + period='. ', is_required=is_required) return '{indent_spacing}- {name} ({type}' \ '{is_required}){description}'.format( From 20cf3931f0eb1762eae660148307b75020125397 Mon Sep 17 00:00:00 2001 From: Shammamah Hossain Date: Fri, 21 Jun 2019 15:29:13 -0400 Subject: [PATCH 18/19] Move logic for determining default value into create_prop_docstring. --- dash/development/_py_components_generation.py | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/dash/development/_py_components_generation.py b/dash/development/_py_components_generation.py index e226136e0d..064896b322 100644 --- a/dash/development/_py_components_generation.py +++ b/dash/development/_py_components_generation.py @@ -251,7 +251,7 @@ def create_docstring(component_name, props, description): else prop['flowType'], required=prop['required'], description=prop['description'], - default=prop.get('defaultValue', {'value': ''})['value'], + default=prop.get('defaultValue'), indent_num=0, is_flow_type='flowType' in prop and 'type' not in prop) for p, prop in list(filter_props(props).items()))) @@ -410,8 +410,10 @@ def create_prop_docstring(prop_name, type_object, required, description, Component is required? description: str Dash component description - default: str - Default value for prop + default: dict + Either None if a default value is not defined, or + dict containing the key 'value' that defines a + default value for the prop indent_num: int Number of indents to use for the context block (creates 2 spaces for every indent) @@ -429,6 +431,11 @@ def create_prop_docstring(prop_name, type_object, required, description, indent_num=indent_num + 1) indent_spacing = ' ' * indent_num + if default is None: + default = '' + else: + default = default['value'] + is_required = 'optional' if required: is_required = 'required' @@ -473,9 +480,7 @@ def shape_or_exact(): type_object=prop, required=prop['required'], description=prop.get('description', ''), - default=prop.get( - 'defaultValue', {'value': ''} - )['value'], + default=prop.get('defaultValue'), indent_num=1 ) for prop_name, prop in list(type_object['value'].items()))) @@ -571,9 +576,7 @@ def map_js_to_py_types_flow_types(type_object): type_object=prop['value'], required=prop['value']['required'], description=prop['value'].get('description', ''), - default=prop.get( - 'defaultValue', {'value': ''} - )['value'], + default=prop.get('defaultValue'), indent_num=indent_num, is_flow_type=True) for prop in type_object['signature']['properties']))), From bf78b4556f0d9b5fb61ae89a43418c0bd047fbd6 Mon Sep 17 00:00:00 2001 From: Shammamah Hossain Date: Fri, 21 Jun 2019 15:41:47 -0400 Subject: [PATCH 19/19] Remove periods from empty descriptions. --- dash/development/_py_components_generation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dash/development/_py_components_generation.py b/dash/development/_py_components_generation.py index 064896b322..3fcd96c89f 100644 --- a/dash/development/_py_components_generation.py +++ b/dash/development/_py_components_generation.py @@ -452,7 +452,7 @@ def create_prop_docstring(prop_name, type_object, required, description, name=prop_name, type=py_type_name, description=description.strip().strip('.'), - period='. ', + period='. ' if description else '', is_required=is_required) return '{indent_spacing}- {name} ({type}' \ '{is_required}){description}'.format(