Skip to content

Commit e77aafb

Browse files
authored
Merge pull request #3142 from plotly/fix/dates-types-id
Fix dates and id typing
2 parents 7caf01e + 3b7dba8 commit e77aafb

File tree

4 files changed

+44
-4
lines changed

4 files changed

+44
-4
lines changed

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+
## [3.0.0-rc2] - UNRELEASED
6+
7+
## Fixed
8+
9+
- [#3142](https://github.com/plotly/dash/pull/3142) Fix typing generation for id and dates props.
10+
511
## [3.0.0-rc1] - 2025-01-28
612

713
## Added

components/dash-core-components/src/fragments/Dropdown.react.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import 'react-virtualized-select/styles.css';
66
import '../components/css/[email protected]';
77
import '../components/css/Dropdown.css';
88

9-
import {propTypes, defaultProps} from '../components/Dropdown.react';
9+
import {propTypes} from '../components/Dropdown.react';
1010
import {sanitizeOptions} from '../utils/optionTypes';
1111
import isEqual from 'react-fast-compare';
1212

@@ -168,6 +168,5 @@ const Dropdown = props => {
168168
};
169169

170170
Dropdown.propTypes = propTypes;
171-
Dropdown.defaultProps = defaultProps;
172171

173172
export default Dropdown;

dash/development/_py_prop_typing.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ def generate_enum(type_info, *_):
120120
def get_prop_typing(
121121
type_name: str, component_name: str, prop_name: str, type_info, namespace=None
122122
):
123+
if prop_name == "id":
124+
# Id is always the same either a string or a dict for pattern matching.
125+
return "typing.Union[str, dict]"
126+
123127
if namespace:
124128
# Only check the namespace once
125129
special = (
@@ -141,7 +145,38 @@ def generate_plotly_figure(*_):
141145
return "typing.Union[Figure, dict]"
142146

143147

144-
special_cases = {"dash_core_components": {"Graph": {"figure": generate_plotly_figure}}}
148+
def generate_datetime_prop(component, array=False):
149+
if "import datetime" not in custom_imports["dash_core_components"][component]:
150+
custom_imports["dash_core_components"][component].append("import datetime")
151+
152+
def generator(*_):
153+
datetime_type = "typing.Union[str, datetime.datetime]"
154+
if array:
155+
datetime_type = f"typing.Sequence[{datetime_type}]"
156+
return datetime_type
157+
158+
return generator
159+
160+
161+
special_cases = {
162+
"dash_core_components": {
163+
"Graph": {"figure": generate_plotly_figure},
164+
"DatePickerRange": {
165+
"start_date": generate_datetime_prop("DatePickerRange"),
166+
"end_date": generate_datetime_prop("DatePickerRange"),
167+
"min_date_allowed": generate_datetime_prop("DatePickerRange"),
168+
"max_date_allowed": generate_datetime_prop("DatePickerRange"),
169+
"disabled_days": generate_datetime_prop("DatePickerRange", True),
170+
},
171+
"DatePickerSingle": {
172+
"date": generate_datetime_prop("DatePickerSingle"),
173+
"min_date_allowed": generate_datetime_prop("DatePickerSingle"),
174+
"max_date_allowed": generate_datetime_prop("DatePickerSingle"),
175+
"disabled_days": generate_datetime_prop("DatePickerSingle", True),
176+
"initial_visible_month": generate_datetime_prop("DatePickerSingle"),
177+
},
178+
}
179+
}
145180

146181

147182
PROP_TYPING = {

tests/unit/development/metadata_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def __init__(
154154
optionalAny: typing.Optional[typing.Any] = None,
155155
customProp: typing.Optional[typing.Any] = None,
156156
customArrayProp: typing.Optional[typing.Sequence[typing.Any]] = None,
157-
id: typing.Optional[str] = None,
157+
id: typing.Optional[typing.Union[str, dict]] = None,
158158
**kwargs
159159
):
160160
self._prop_names = ['children', 'id', 'aria-*', 'customArrayProp', 'customProp', 'data-*', 'in', 'optionalAny', 'optionalArray', 'optionalArrayOf', 'optionalBool', 'optionalElement', 'optionalEnum', 'optionalNode', 'optionalNumber', 'optionalObject', 'optionalObjectOf', 'optionalObjectWithExactAndNestedDescription', 'optionalObjectWithShapeAndNestedDescription', 'optionalString', 'optionalUnion']

0 commit comments

Comments
 (0)