Skip to content

Commit ad0f638

Browse files
updates for flow types
1 parent f224c17 commit ad0f638

File tree

2 files changed

+54
-65
lines changed

2 files changed

+54
-65
lines changed

dash/development/_py_components_generation.py

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ def create_prop_docstring(
455455
dict_part2 = "".join([desc_indent, "Or", dict_part2])
456456
dict_descr = "{} \n\n {}".format(dict_part1, dict_part2)
457457

458-
# ensures indent is correct if there is a second nested dict
458+
# ensures indent is correct if there is a second nested list of dicts
459459
current_indent = dict_descr.lstrip("\n").find("-")
460460
if current_indent == len(indent_spacing) + 4:
461461
dict_descr = "".join(" " + line for line in dict_descr.splitlines(True))
@@ -576,24 +576,18 @@ def map_js_to_py_types_flow_types(type_object):
576576
else ""
577577
),
578578
# React's PropTypes.shape
579-
signature=lambda indent_num: "dict with keys: {}.\n{}".format(
580-
", ".join(
581-
"'{}'".format(d["key"]) for d in type_object["signature"]["properties"]
582-
),
583-
"{}Those keys have the following types:\n{}".format(
584-
" " * indent_num,
585-
"\n".join(
586-
create_prop_docstring(
587-
prop_name=prop["key"],
588-
type_object=prop["value"],
589-
required=prop["value"]["required"],
590-
description=prop["value"].get("description", ""),
591-
default=prop.get("defaultValue"),
592-
indent_num=indent_num + 2,
593-
is_flow_type=True,
594-
)
595-
for prop in type_object["signature"]["properties"]
596-
),
579+
signature=lambda indent_num: "dict with keys: \n{}".format(
580+
" \n".join(
581+
create_prop_docstring(
582+
prop_name=prop["key"],
583+
type_object=prop["value"],
584+
required=prop["value"]["required"],
585+
description=prop["value"].get("description", ""),
586+
default=prop.get("defaultValue"),
587+
indent_num=indent_num + 2,
588+
is_flow_type=True,
589+
)
590+
for prop in type_object["signature"]["properties"]
597591
),
598592
),
599593
)

tests/unit/development/test_flow_metadata_conversions.py

Lines changed: 41 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,17 @@
2828
"optionalSignature(shape)",
2929
"\n".join(
3030
[
31-
"dict with keys: 'checked', 'children', 'customData', 'disabled', 'label', 'primaryText', 'secondaryText', 'style', 'value'.",
32-
"Those keys have the following types:\n",
33-
" - checked (boolean; optional)\n",
34-
" - children (a list of or a singular dash component, string or number; optional)\n",
31+
"dict with keys: \n",
32+
" - checked (boolean; optional) \n",
33+
" - children (a list of or a singular dash component, string or number; optional) \n",
3534
" - customData (bool | number | str | dict | list; required):\n"
36-
" A test description. \n",
37-
" - disabled (boolean; optional)\n",
38-
" - label (string; optional)\n",
35+
" A test description. \n",
36+
" - disabled (boolean; optional) \n",
37+
" - label (string; optional) \n",
3938
" - primaryText (string; required):\n"
40-
" Another test description. \n",
41-
" - secondaryText (string; optional)\n",
42-
" - style (dict; optional)\n",
39+
" Another test description. \n",
40+
" - secondaryText (string; optional) \n",
41+
" - style (dict; optional) \n",
4342
" - value (bool | number | str | dict | list; required)",
4443
]
4544
),
@@ -48,20 +47,18 @@
4847
"requiredNested",
4948
"\n".join(
5049
[
51-
"dict with keys: 'customData', 'value'.",
52-
"Those keys have the following types:\n",
50+
"dict with keys: \n",
5351
" - customData (dict; required) \n\n"
54-
" `customData` is a dict with keys: 'checked', 'children', 'customData', 'disabled', 'label', 'primaryText', 'secondaryText', 'style', 'value'.",
55-
" Those keys have the following types:\n",
56-
" - checked (boolean; optional)\n",
57-
" - children (a list of or a singular dash component, string or number; optional)\n",
58-
" - customData (bool | number | str | dict | list; required)\n",
59-
" - disabled (boolean; optional)\n",
60-
" - label (string; optional)\n",
61-
" - primaryText (string; required)\n",
62-
" - secondaryText (string; optional)\n",
63-
" - style (dict; optional)\n",
64-
" - value (bool | number | str | dict | list; required)\n",
52+
" `customData` is a dict with keys: \n",
53+
" - checked (boolean; optional) \n",
54+
" - children (a list of or a singular dash component, string or number; optional) \n",
55+
" - customData (bool | number | str | dict | list; required) \n",
56+
" - disabled (boolean; optional) \n",
57+
" - label (string; optional) \n",
58+
" - primaryText (string; required) \n",
59+
" - secondaryText (string; optional) \n",
60+
" - style (dict; optional) \n",
61+
" - value (bool | number | str | dict | list; required) \n",
6562
" - value (bool | number | str | dict | list; required)",
6663
]
6764
),
@@ -90,26 +87,25 @@
9087
"- optionalSignature(shape) (dict; optional):",
9188
" This is a test of an object's shape. ",
9289
"",
93-
" `optionalSignature(shape)` is a dict with keys: 'checked', 'children', 'customData', 'disabled', 'label', 'primaryText', 'secondaryText', 'style', 'value'.",
94-
"Those keys have the following types:",
90+
" `optionalSignature(shape)` is a dict with keys: ",
9591
"",
96-
" - checked (boolean; optional)",
92+
" - checked (boolean; optional) ",
9793
"",
98-
" - children (a list of or a singular dash component, string or number; optional)",
94+
" - children (a list of or a singular dash component, string or number; optional) ",
9995
"",
10096
" - customData (bool | number | str | dict | list; required):",
101-
" A test description. ",
97+
" A test description. ",
10298
"",
103-
" - disabled (boolean; optional)",
99+
" - disabled (boolean; optional) ",
104100
"",
105-
" - label (string; optional)",
101+
" - label (string; optional) ",
106102
"",
107103
" - primaryText (string; required):",
108-
" Another test description. ",
104+
" Another test description. ",
109105
"",
110-
" - secondaryText (string; optional)",
106+
" - secondaryText (string; optional) ",
111107
"",
112-
" - style (dict; optional)",
108+
" - style (dict; optional) ",
113109
"",
114110
" - value (bool | number | str | dict | list; required)",
115111
"",
@@ -118,31 +114,29 @@
118114
"",
119115
"- requiredNested (dict; required) ",
120116
"",
121-
" `requiredNested` is a dict with keys: 'customData', 'value'.",
122-
"Those keys have the following types:",
117+
" `requiredNested` is a dict with keys: ",
123118
"",
124119
" - customData (dict; required) ",
125120
"",
126-
" `customData` is a dict with keys: 'checked', 'children', 'customData', 'disabled', 'label', 'primaryText', 'secondaryText', 'style', 'value'.",
127-
" Those keys have the following types:",
121+
" `customData` is a dict with keys: ",
128122
"",
129-
" - checked (boolean; optional)",
123+
" - checked (boolean; optional) ",
130124
"",
131-
" - children (a list of or a singular dash component, string or number; optional)",
125+
" - children (a list of or a singular dash component, string or number; optional) ",
132126
"",
133-
" - customData (bool | number | str | dict | list; required)",
127+
" - customData (bool | number | str | dict | list; required) ",
134128
"",
135-
" - disabled (boolean; optional)",
129+
" - disabled (boolean; optional) ",
136130
"",
137-
" - label (string; optional)",
131+
" - label (string; optional) ",
138132
"",
139-
" - primaryText (string; required)",
133+
" - primaryText (string; required) ",
140134
"",
141-
" - secondaryText (string; optional)",
135+
" - secondaryText (string; optional) ",
142136
"",
143-
" - style (dict; optional)",
137+
" - style (dict; optional) ",
144138
"",
145-
" - value (bool | number | str | dict | list; required)",
139+
" - value (bool | number | str | dict | list; required) ",
146140
"",
147141
" - value (bool | number | str | dict | list; required)",
148142
"",
@@ -168,6 +162,7 @@ def test_docstring(load_test_flow_metadata_json):
168162
load_test_flow_metadata_json["props"],
169163
load_test_flow_metadata_json["description"],
170164
)
165+
print(docstring.splitlines())
171166
prohibit_events(load_test_flow_metadata_json["props"]),
172167
assert not list(unified_diff(expected_doc, docstring.splitlines()))
173168

0 commit comments

Comments
 (0)