Skip to content

Commit c593ea0

Browse files
remove trailing whitespace
1 parent ad0f638 commit c593ea0

File tree

6 files changed

+107
-104
lines changed

6 files changed

+107
-104
lines changed

dash/development/_py_components_generation.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ def create_prop_docstring(
429429
break_long_words=False,
430430
break_on_hyphens=False,
431431
)
432-
description = "\n{} ".format(description) if description else ""
432+
description = "\n{}".format(description) if description else ""
433433
colon = ":" if description else ""
434434
description = fix_keywords(description)
435435

@@ -450,20 +450,21 @@ def create_prop_docstring(
450450

451451
# captures optional nested dict description and puts the "or" condition on a new line
452452
if "| dict with keys:" in dict_descr:
453-
dict_part1, dict_part2 = dict_descr.split("|", 1)
454-
dict_part1 = dict_part1 + " "
453+
dict_part1, dict_part2 = dict_descr.split(" |", 1)
455454
dict_part2 = "".join([desc_indent, "Or", dict_part2])
456-
dict_descr = "{} \n\n {}".format(dict_part1, dict_part2)
455+
dict_descr = "{}\n\n {}".format(dict_part1, dict_part2)
457456

458457
# ensures indent is correct if there is a second nested list of dicts
459458
current_indent = dict_descr.lstrip("\n").find("-")
460-
if current_indent == len(indent_spacing) + 4:
461-
dict_descr = "".join(" " + line for line in dict_descr.splitlines(True))
459+
if current_indent == len(indent_spacing):
460+
dict_descr = "".join(
461+
"\n\n " + line for line in dict_descr.splitlines() if line != ""
462+
)
462463

463464
return (
464465
"\n{indent_spacing}- {name} ({dict_or_list}; {is_required}){colon}"
465-
"{description} "
466-
"\n\n{intro} {dict_descr}".format(
466+
"{description}"
467+
"\n\n{intro}{dict_descr}".format(
467468
indent_spacing=indent_spacing,
468469
name=prop_name,
469470
colon=colon,
@@ -491,8 +492,8 @@ def map_js_to_py_types_prop_types(type_object, indent_num):
491492
"""Mapping from the PropTypes js type object to the Python type."""
492493

493494
def shape_or_exact():
494-
return "dict with keys: \n{}".format(
495-
" \n".join(
495+
return "dict with keys:\n{}".format(
496+
"\n".join(
496497
create_prop_docstring(
497498
prop_name=prop_name,
498499
type_object=prop,
@@ -576,8 +577,8 @@ def map_js_to_py_types_flow_types(type_object):
576577
else ""
577578
),
578579
# React's PropTypes.shape
579-
signature=lambda indent_num: "dict with keys: \n{}".format(
580-
" \n".join(
580+
signature=lambda indent_num: "dict with keys:\n{}".format(
581+
"\n".join(
581582
create_prop_docstring(
582583
prop_name=prop["key"],
583584
type_object=prop["value"],

tests/unit/development/__init__.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def has_trailing_space(s):
3131
"- optionalAny (boolean | number | string | dict | list; optional)",
3232
"",
3333
"- optionalArray (list; optional):",
34-
" Description of optionalArray. ",
34+
" Description of optionalArray.",
3535
"",
3636
"- optionalArrayOf (list of numbers; optional)",
3737
"",
@@ -49,41 +49,41 @@ def has_trailing_space(s):
4949
"",
5050
"- optionalObjectOf (dict with strings as keys and values of type number; optional)",
5151
"",
52-
"- optionalObjectWithExactAndNestedDescription (dict; optional) ",
52+
"- optionalObjectWithExactAndNestedDescription (dict; optional)",
5353
"",
54-
" `optionalObjectWithExactAndNestedDescription` is a dict with keys: ",
54+
" `optionalObjectWithExactAndNestedDescription` is a dict with keys:",
5555
"",
56-
" - color (string; optional) ",
56+
" - color (string; optional)",
5757
"",
5858
" - figure (dict; optional):",
59-
" Figure is a plotly graph object. ",
59+
" Figure is a plotly graph object.",
6060
"",
61-
" `figure` is a dict with keys: ",
61+
" `figure` is a dict with keys:",
6262
"",
6363
" - data (list of dicts; optional):",
64-
" data is a collection of traces. ",
64+
" data is a collection of traces.",
6565
"",
6666
" - layout (dict; optional):",
67-
" layout describes the rest of the figure. ",
67+
" layout describes the rest of the figure.",
6868
"",
6969
" - fontSize (number; optional)",
7070
"",
71-
"- optionalObjectWithShapeAndNestedDescription (dict; optional) ",
71+
"- optionalObjectWithShapeAndNestedDescription (dict; optional)",
7272
"",
73-
" `optionalObjectWithShapeAndNestedDescription` is a dict with keys: ",
73+
" `optionalObjectWithShapeAndNestedDescription` is a dict with keys:",
7474
"",
75-
" - color (string; optional) ",
75+
" - color (string; optional)",
7676
"",
7777
" - figure (dict; optional):",
78-
" Figure is a plotly graph object. ",
78+
" Figure is a plotly graph object.",
7979
"",
80-
" `figure` is a dict with keys: ",
80+
" `figure` is a dict with keys:",
8181
"",
8282
" - data (list of dicts; optional):",
83-
" data is a collection of traces. ",
83+
" data is a collection of traces.",
8484
"",
8585
" - layout (dict; optional):",
86-
" layout describes the rest of the figure. ",
86+
" layout describes the rest of the figure.",
8787
"",
8888
" - fontSize (number; optional)",
8989
"",

tests/unit/development/metadata_test.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Table(Component):
2727
- optionalAny (boolean | number | string | dict | list; optional)
2828
2929
- optionalArray (list; optional):
30-
Description of optionalArray.
30+
Description of optionalArray.
3131
3232
- optionalArrayOf (list of numbers; optional)
3333
@@ -45,41 +45,41 @@ class Table(Component):
4545
4646
- optionalObjectOf (dict with strings as keys and values of type number; optional)
4747
48-
- optionalObjectWithExactAndNestedDescription (dict; optional)
48+
- optionalObjectWithExactAndNestedDescription (dict; optional)
4949
50-
`optionalObjectWithExactAndNestedDescription` is a dict with keys:
50+
`optionalObjectWithExactAndNestedDescription` is a dict with keys:
5151
52-
- color (string; optional)
52+
- color (string; optional)
5353
5454
- figure (dict; optional):
55-
Figure is a plotly graph object.
55+
Figure is a plotly graph object.
5656
57-
`figure` is a dict with keys:
57+
`figure` is a dict with keys:
5858
5959
- data (list of dicts; optional):
60-
data is a collection of traces.
60+
data is a collection of traces.
6161
6262
- layout (dict; optional):
63-
layout describes the rest of the figure.
63+
layout describes the rest of the figure.
6464
6565
- fontSize (number; optional)
6666
67-
- optionalObjectWithShapeAndNestedDescription (dict; optional)
67+
- optionalObjectWithShapeAndNestedDescription (dict; optional)
6868
69-
`optionalObjectWithShapeAndNestedDescription` is a dict with keys:
69+
`optionalObjectWithShapeAndNestedDescription` is a dict with keys:
7070
71-
- color (string; optional)
71+
- color (string; optional)
7272
7373
- figure (dict; optional):
74-
Figure is a plotly graph object.
74+
Figure is a plotly graph object.
7575
76-
`figure` is a dict with keys:
76+
`figure` is a dict with keys:
7777
7878
- data (list of dicts; optional):
79-
data is a collection of traces.
79+
data is a collection of traces.
8080
8181
- layout (dict; optional):
82-
layout describes the rest of the figure.
82+
layout describes the rest of the figure.
8383
8484
- fontSize (number; optional)
8585

tests/unit/development/test_flow_metadata_conversions.py

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,17 @@
2828
"optionalSignature(shape)",
2929
"\n".join(
3030
[
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",
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",
3434
" - customData (bool | number | str | dict | list; required):\n"
35-
" A test description. \n",
36-
" - disabled (boolean; optional) \n",
37-
" - label (string; optional) \n",
35+
" A test description.\n",
36+
" - disabled (boolean; optional)\n",
37+
" - label (string; optional)\n",
3838
" - primaryText (string; required):\n"
39-
" Another test description. \n",
40-
" - secondaryText (string; optional) \n",
41-
" - style (dict; optional) \n",
39+
" Another test description.\n",
40+
" - secondaryText (string; optional)\n",
41+
" - style (dict; optional)\n",
4242
" - value (bool | number | str | dict | list; required)",
4343
]
4444
),
@@ -47,18 +47,18 @@
4747
"requiredNested",
4848
"\n".join(
4949
[
50-
"dict with keys: \n",
51-
" - customData (dict; required) \n\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",
50+
"dict with keys:\n",
51+
" - customData (dict; required)\n\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",
6262
" - value (bool | number | str | dict | list; required)",
6363
]
6464
),
@@ -76,72 +76,72 @@
7676
"- optionalArray (list; optional):",
7777
" An array test with a particularly long description that covers",
7878
" several lines. It includes the newline character and should span",
79-
" 3 lines in total. ",
79+
" 3 lines in total.",
8080
"",
8181
"- optionalBoolean (boolean; default False):",
82-
" A boolean test. ",
82+
" A boolean test.",
8383
"",
8484
"- optionalNode (a list of or a singular dash component, string or number; optional):",
85-
" A node test. ",
85+
" A node test.",
8686
"",
8787
"- optionalSignature(shape) (dict; optional):",
88-
" This is a test of an object's shape. ",
88+
" This is a test of an object's shape.",
8989
"",
90-
" `optionalSignature(shape)` is a dict with keys: ",
90+
" `optionalSignature(shape)` is a dict with keys:",
9191
"",
92-
" - checked (boolean; optional) ",
92+
" - checked (boolean; optional)",
9393
"",
94-
" - 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)",
9595
"",
9696
" - customData (bool | number | str | dict | list; required):",
97-
" A test description. ",
97+
" A test description.",
9898
"",
99-
" - disabled (boolean; optional) ",
99+
" - disabled (boolean; optional)",
100100
"",
101-
" - label (string; optional) ",
101+
" - label (string; optional)",
102102
"",
103103
" - primaryText (string; required):",
104-
" Another test description. ",
104+
" Another test description.",
105105
"",
106-
" - secondaryText (string; optional) ",
106+
" - secondaryText (string; optional)",
107107
"",
108-
" - style (dict; optional) ",
108+
" - style (dict; optional)",
109109
"",
110110
" - value (bool | number | str | dict | list; required)",
111111
"",
112112
"- optionalString (string; default ''):",
113-
" A string that isn't required. ",
113+
" A string that isn't required.",
114114
"",
115-
"- requiredNested (dict; required) ",
115+
"- requiredNested (dict; required)",
116116
"",
117-
" `requiredNested` is a dict with keys: ",
117+
" `requiredNested` is a dict with keys:",
118118
"",
119-
" - customData (dict; required) ",
119+
" - customData (dict; required)",
120120
"",
121-
" `customData` is a dict with keys: ",
121+
" `customData` is a dict with keys:",
122122
"",
123-
" - checked (boolean; optional) ",
123+
" - checked (boolean; optional)",
124124
"",
125-
" - 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)",
126126
"",
127-
" - customData (bool | number | str | dict | list; required) ",
127+
" - customData (bool | number | str | dict | list; required)",
128128
"",
129-
" - disabled (boolean; optional) ",
129+
" - disabled (boolean; optional)",
130130
"",
131-
" - label (string; optional) ",
131+
" - label (string; optional)",
132132
"",
133-
" - primaryText (string; required) ",
133+
" - primaryText (string; required)",
134134
"",
135-
" - secondaryText (string; optional) ",
135+
" - secondaryText (string; optional)",
136136
"",
137-
" - style (dict; optional) ",
137+
" - style (dict; optional)",
138138
"",
139-
" - value (bool | number | str | dict | list; required) ",
139+
" - value (bool | number | str | dict | list; required)",
140140
"",
141141
" - value (bool | number | str | dict | list; required)",
142142
"",
143143
"- requiredString (string; required):",
144-
" A required string. ",
144+
" A required string.",
145145
"",
146146
"- requiredUnion (string | number; required)",
147147
]

tests/unit/development/test_generate_class_file.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
generate_class_string,
1010
generate_class_file,
1111
)
12-
from . import _dir
12+
from . import _dir, has_trailing_space
1313

1414
# Import string not included in generated class string
1515
import_string = (
@@ -67,6 +67,7 @@ def test_class_string(expected_class_string, component_class_string):
6767
expected_class_string.splitlines(), component_class_string.splitlines()
6868
)
6969
)
70+
assert not has_trailing_space(component_class_string)
7071

7172

7273
def test_class_file(expected_class_string, written_class_string):
@@ -75,3 +76,4 @@ def test_class_file(expected_class_string, written_class_string):
7576
expected_class_string.splitlines(), written_class_string.splitlines()
7677
)
7778
)
79+
assert not has_trailing_space(written_class_string)

0 commit comments

Comments
 (0)