Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep doc-string order for shape or exact props #2994

Merged
merged 7 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import React from 'react';
import PropTypes from 'prop-types';

const ShapeOrExactKeepOrderComponent = (props) => {
const { id } = props;

return (
<div id={id} />
);
};

ShapeOrExactKeepOrderComponent.propTypes = {
id: PropTypes.string,
/**
* test prop for shape
*/
shape_test_prop: PropTypes.shape({
/**
* z
*/
z: PropTypes.string,
/**
* a
*/
a: PropTypes.string,
/**
* y
*/
y: PropTypes.string
}),
/**
* test prop for exact
*/
exact_test_prop: PropTypes.exact({
/**
* z
*/
z: PropTypes.string,
/**
* a
*/
a: PropTypes.string,
/**
* y
*/
y: PropTypes.string
}),
};

export default ShapeOrExactKeepOrderComponent;
4 changes: 3 additions & 1 deletion @plotly/dash-test-components/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import ComponentAsProp from './components/ComponentAsProp';
import DrawCounter from './components/DrawCounter';
import AddPropsComponent from "./components/AddPropsComponent";
import ReceivePropsComponent from "./components/ReceivePropsComponent";
import ShapeOrExactKeepOrderComponent from "./components/ShapeOrExactKeepOrderComponent";


export {
Expand All @@ -25,5 +26,6 @@ export {
ComponentAsProp,
DrawCounter,
AddPropsComponent,
ReceivePropsComponent
ReceivePropsComponent,
ShapeOrExactKeepOrderComponent
};
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
All notable changes to `dash` will be documented in this file.
This project adheres to [Semantic Versioning](https://semver.org/).

## [UNRELEASED]

## Fixed

- [#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)

## [2.18.1] - 2024-09-12

## Fixed
Expand Down
2 changes: 1 addition & 1 deletion dash/development/_py_components_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ def shape_or_exact():
default=prop.get("defaultValue"),
indent_num=indent_num + 2,
)
for prop_name, prop in sorted(list(type_object["value"].items()))
for prop_name, prop in type_object["value"].items()
)

def array_of():
Expand Down
10 changes: 5 additions & 5 deletions tests/unit/development/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def has_trailing_space(s):
"",
"- optionalElement (dash component; optional)",
"",
"- optionalEnum (a value equal to: 'News'," " 'Photos'; optional)",
"- optionalEnum (a value equal to: 'News', 'Photos'; optional)",
"",
"- optionalNode (a list of or a singular dash component, string or number; optional)",
"",
Expand All @@ -55,6 +55,8 @@ def has_trailing_space(s):
"",
" - color (string; optional)",
"",
" - fontSize (number; optional)",
"",
" - figure (dict; optional):",
" Figure is a plotly graph object.",
"",
Expand All @@ -66,14 +68,14 @@ def has_trailing_space(s):
" - layout (dict; optional):",
" layout describes the rest of the figure.",
"",
" - fontSize (number; optional)",
"",
"- optionalObjectWithShapeAndNestedDescription (dict; optional)",
"",
" `optionalObjectWithShapeAndNestedDescription` is a dict with keys:",
"",
" - color (string; optional)",
"",
" - fontSize (number; optional)",
"",
" - figure (dict; optional):",
" Figure is a plotly graph object.",
"",
Expand All @@ -85,8 +87,6 @@ def has_trailing_space(s):
" - layout (dict; optional):",
" layout describes the rest of the figure.",
"",
" - fontSize (number; optional)",
"",
"- optionalString (string; default 'hello world')",
"",
"- optionalUnion (string | number; optional)",
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/development/metadata_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class Table(Component):

- color (string; optional)

- fontSize (number; optional)

- figure (dict; optional):
Figure is a plotly graph object.

Expand All @@ -62,14 +64,14 @@ class Table(Component):
- layout (dict; optional):
layout describes the rest of the figure.

- fontSize (number; optional)

- optionalObjectWithShapeAndNestedDescription (dict; optional)

`optionalObjectWithShapeAndNestedDescription` is a dict with keys:

- color (string; optional)

- fontSize (number; optional)

- figure (dict; optional):
Figure is a plotly graph object.

Expand All @@ -81,8 +83,6 @@ class Table(Component):
- layout (dict; optional):
layout describes the rest of the figure.

- fontSize (number; optional)

- optionalString (string; default 'hello world')

- optionalUnion (string | number; optional)"""
Expand Down
41 changes: 5 additions & 36 deletions tests/unit/development/test_metadata_conversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,62 +10,32 @@

expected_arg_strings = OrderedDict(
[
["children", "a list of or a singular dash component, string or number"],
["optionalArray", "list"],
["optionalBool", "boolean"],
["optionalFunc", ""],
["optionalNumber", "number"],
["optionalObject", "dict"],
["optionalString", "string"],
["optionalSymbol", ""],
["optionalElement", "dash component"],
["optionalNode", "a list of or a singular dash component, string or number"],
["optionalElement", "dash component"],
["optionalMessage", ""],
["optionalEnum", "a value equal to: 'News', 'Photos'"],
["optionalUnion", "string | number"],
["optionalArrayOf", "list of numbers"],
["optionalObjectOf", "dict with strings as keys and values of type number"],
[
"optionalObjectWithExactAndNestedDescription",
"\n".join(
[
"dict with keys:\n",
" - color (string; optional)\n",
" - figure (dict; optional):",
" Figure is a plotly graph object.\n",
" `figure` is a dict with keys:\n",
# noqa: E501
" - data (list of dicts; optional):",
" data is a collection of traces.\n",
" - layout (dict; optional):",
" layout describes the rest of the figure.\n",
# noqa: E501
" - fontSize (number; optional)",
]
),
"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.",
],
[
"optionalObjectWithShapeAndNestedDescription",
"\n".join(
[
"dict with keys:\n",
" - color (string; optional)\n",
" - figure (dict; optional):",
" Figure is a plotly graph object.\n",
" `figure` is a dict with keys:\n",
# noqa: E501
" - data (list of dicts; optional):",
" data is a collection of traces.\n",
" - layout (dict; optional):",
" layout describes the rest of the figure.\n",
# noqa: E501
" - fontSize (number; optional)",
],
),
"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.",
],
["optionalAny", "boolean | number | string | dict | list"],
["customProp", ""],
["customArrayProp", "list"],
["children", "a list of or a singular dash component, string or number"],
["data-*", "string"],
["aria-*", "string"],
["in", "string"],
Expand All @@ -80,12 +50,11 @@ def test_docstring(load_test_metadata_json):
load_test_metadata_json["props"],
load_test_metadata_json["description"],
)
prohibit_events(load_test_metadata_json["props"]),
(prohibit_events(load_test_metadata_json["props"]),)
assert not list(unified_diff(expected_table_component_doc, docstring.splitlines()))


def test_docgen_to_python_args(load_test_metadata_json):
props = load_test_metadata_json["props"]

for prop_name, prop in list(props.items()):
assert js_to_py_type(prop["type"]) == expected_arg_strings[prop_name]