Skip to content

Commit 288652c

Browse files
authored
Merge pull request #2994 from CNFeffery/dev
Keep doc-string order for shape or exact props
2 parents 438132f + 1a54867 commit 288652c

File tree

7 files changed

+74
-47
lines changed

7 files changed

+74
-47
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
4+
const ShapeOrExactKeepOrderComponent = (props) => {
5+
const { id } = props;
6+
7+
return (
8+
<div id={id} />
9+
);
10+
};
11+
12+
ShapeOrExactKeepOrderComponent.propTypes = {
13+
id: PropTypes.string,
14+
/**
15+
* test prop for shape
16+
*/
17+
shape_test_prop: PropTypes.shape({
18+
/**
19+
* z
20+
*/
21+
z: PropTypes.string,
22+
/**
23+
* a
24+
*/
25+
a: PropTypes.string,
26+
/**
27+
* y
28+
*/
29+
y: PropTypes.string
30+
}),
31+
/**
32+
* test prop for exact
33+
*/
34+
exact_test_prop: PropTypes.exact({
35+
/**
36+
* z
37+
*/
38+
z: PropTypes.string,
39+
/**
40+
* a
41+
*/
42+
a: PropTypes.string,
43+
/**
44+
* y
45+
*/
46+
y: PropTypes.string
47+
}),
48+
};
49+
50+
export default ShapeOrExactKeepOrderComponent;

@plotly/dash-test-components/src/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import ComponentAsProp from './components/ComponentAsProp';
1111
import DrawCounter from './components/DrawCounter';
1212
import AddPropsComponent from "./components/AddPropsComponent";
1313
import ReceivePropsComponent from "./components/ReceivePropsComponent";
14+
import ShapeOrExactKeepOrderComponent from "./components/ShapeOrExactKeepOrderComponent";
1415

1516

1617
export {
@@ -25,5 +26,6 @@ export {
2526
ComponentAsProp,
2627
DrawCounter,
2728
AddPropsComponent,
28-
ReceivePropsComponent
29+
ReceivePropsComponent,
30+
ShapeOrExactKeepOrderComponent
2931
};

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
All notable changes to `dash` will be documented in this file.
33
This project adheres to [Semantic Versioning](https://semver.org/).
44

5+
## [UNRELEASED]
6+
7+
## Fixed
8+
9+
- [#2994](https://github.com/plotly/dash/pull/2994) Keep generated doc-string order for shape or exact props. Fixes [#2990](https://github.com/plotly/dash/issues/2990)
10+
511
## [2.18.1] - 2024-09-12
612

713
## Fixed

dash/development/_py_components_generation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ def shape_or_exact():
557557
default=prop.get("defaultValue"),
558558
indent_num=indent_num + 2,
559559
)
560-
for prop_name, prop in sorted(list(type_object["value"].items()))
560+
for prop_name, prop in type_object["value"].items()
561561
)
562562

563563
def array_of():

tests/unit/development/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def has_trailing_space(s):
3939
"",
4040
"- optionalElement (dash component; optional)",
4141
"",
42-
"- optionalEnum (a value equal to: 'News'," " 'Photos'; optional)",
42+
"- optionalEnum (a value equal to: 'News', 'Photos'; optional)",
4343
"",
4444
"- optionalNode (a list of or a singular dash component, string or number; optional)",
4545
"",
@@ -55,6 +55,8 @@ def has_trailing_space(s):
5555
"",
5656
" - color (string; optional)",
5757
"",
58+
" - fontSize (number; optional)",
59+
"",
5860
" - figure (dict; optional):",
5961
" Figure is a plotly graph object.",
6062
"",
@@ -66,14 +68,14 @@ def has_trailing_space(s):
6668
" - layout (dict; optional):",
6769
" layout describes the rest of the figure.",
6870
"",
69-
" - fontSize (number; optional)",
70-
"",
7171
"- optionalObjectWithShapeAndNestedDescription (dict; optional)",
7272
"",
7373
" `optionalObjectWithShapeAndNestedDescription` is a dict with keys:",
7474
"",
7575
" - color (string; optional)",
7676
"",
77+
" - fontSize (number; optional)",
78+
"",
7779
" - figure (dict; optional):",
7880
" Figure is a plotly graph object.",
7981
"",
@@ -85,8 +87,6 @@ def has_trailing_space(s):
8587
" - layout (dict; optional):",
8688
" layout describes the rest of the figure.",
8789
"",
88-
" - fontSize (number; optional)",
89-
"",
9090
"- optionalString (string; default 'hello world')",
9191
"",
9292
"- optionalUnion (string | number; optional)",

tests/unit/development/metadata_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ class Table(Component):
5151
5252
- color (string; optional)
5353
54+
- fontSize (number; optional)
55+
5456
- figure (dict; optional):
5557
Figure is a plotly graph object.
5658
@@ -62,14 +64,14 @@ class Table(Component):
6264
- layout (dict; optional):
6365
layout describes the rest of the figure.
6466
65-
- fontSize (number; optional)
66-
6767
- optionalObjectWithShapeAndNestedDescription (dict; optional)
6868
6969
`optionalObjectWithShapeAndNestedDescription` is a dict with keys:
7070
7171
- color (string; optional)
7272
73+
- fontSize (number; optional)
74+
7375
- figure (dict; optional):
7476
Figure is a plotly graph object.
7577
@@ -81,8 +83,6 @@ class Table(Component):
8183
- layout (dict; optional):
8284
layout describes the rest of the figure.
8385
84-
- fontSize (number; optional)
85-
8686
- optionalString (string; default 'hello world')
8787
8888
- optionalUnion (string | number; optional)"""

tests/unit/development/test_metadata_conversions.py

Lines changed: 5 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -10,62 +10,32 @@
1010

1111
expected_arg_strings = OrderedDict(
1212
[
13-
["children", "a list of or a singular dash component, string or number"],
1413
["optionalArray", "list"],
1514
["optionalBool", "boolean"],
1615
["optionalFunc", ""],
1716
["optionalNumber", "number"],
1817
["optionalObject", "dict"],
1918
["optionalString", "string"],
2019
["optionalSymbol", ""],
21-
["optionalElement", "dash component"],
2220
["optionalNode", "a list of or a singular dash component, string or number"],
21+
["optionalElement", "dash component"],
2322
["optionalMessage", ""],
2423
["optionalEnum", "a value equal to: 'News', 'Photos'"],
2524
["optionalUnion", "string | number"],
2625
["optionalArrayOf", "list of numbers"],
2726
["optionalObjectOf", "dict with strings as keys and values of type number"],
2827
[
2928
"optionalObjectWithExactAndNestedDescription",
30-
"\n".join(
31-
[
32-
"dict with keys:\n",
33-
" - color (string; optional)\n",
34-
" - figure (dict; optional):",
35-
" Figure is a plotly graph object.\n",
36-
" `figure` is a dict with keys:\n",
37-
# noqa: E501
38-
" - data (list of dicts; optional):",
39-
" data is a collection of traces.\n",
40-
" - layout (dict; optional):",
41-
" layout describes the rest of the figure.\n",
42-
# noqa: E501
43-
" - fontSize (number; optional)",
44-
]
45-
),
29+
"dict with keys:\n\n - color (string; optional)\n\n - fontSize (number; optional)\n\n - figure (dict; optional):\n Figure is a plotly graph object.\n\n `figure` is a dict with keys:\n\n - data (list of dicts; optional):\n data is a collection of traces.\n\n - layout (dict; optional):\n layout describes the rest of the figure.",
4630
],
4731
[
4832
"optionalObjectWithShapeAndNestedDescription",
49-
"\n".join(
50-
[
51-
"dict with keys:\n",
52-
" - color (string; optional)\n",
53-
" - figure (dict; optional):",
54-
" Figure is a plotly graph object.\n",
55-
" `figure` is a dict with keys:\n",
56-
# noqa: E501
57-
" - data (list of dicts; optional):",
58-
" data is a collection of traces.\n",
59-
" - layout (dict; optional):",
60-
" layout describes the rest of the figure.\n",
61-
# noqa: E501
62-
" - fontSize (number; optional)",
63-
],
64-
),
33+
"dict with keys:\n\n - color (string; optional)\n\n - fontSize (number; optional)\n\n - figure (dict; optional):\n Figure is a plotly graph object.\n\n `figure` is a dict with keys:\n\n - data (list of dicts; optional):\n data is a collection of traces.\n\n - layout (dict; optional):\n layout describes the rest of the figure.",
6534
],
6635
["optionalAny", "boolean | number | string | dict | list"],
6736
["customProp", ""],
6837
["customArrayProp", "list"],
38+
["children", "a list of or a singular dash component, string or number"],
6939
["data-*", "string"],
7040
["aria-*", "string"],
7141
["in", "string"],
@@ -80,12 +50,11 @@ def test_docstring(load_test_metadata_json):
8050
load_test_metadata_json["props"],
8151
load_test_metadata_json["description"],
8252
)
83-
prohibit_events(load_test_metadata_json["props"]),
53+
(prohibit_events(load_test_metadata_json["props"]),)
8454
assert not list(unified_diff(expected_table_component_doc, docstring.splitlines()))
8555

8656

8757
def test_docgen_to_python_args(load_test_metadata_json):
8858
props = load_test_metadata_json["props"]
89-
9059
for prop_name, prop in list(props.items()):
9160
assert js_to_py_type(prop["type"]) == expected_arg_strings[prop_name]

0 commit comments

Comments
 (0)