diff --git a/CHANGELOG.md b/CHANGELOG.md index 9646d46e95..e98c86fad0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ All notable changes to `dash` will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org/). +## [3.0.0-rc2] - UNRELEASED + +## Fixed + +- [#3142](https://github.com/plotly/dash/pull/3142) Fix typing generation for id and dates props. + ## [3.0.0-rc1] - 2025-01-28 ## Added diff --git a/components/dash-core-components/src/fragments/Dropdown.react.js b/components/dash-core-components/src/fragments/Dropdown.react.js index a4ccd9a003..4d003863fd 100644 --- a/components/dash-core-components/src/fragments/Dropdown.react.js +++ b/components/dash-core-components/src/fragments/Dropdown.react.js @@ -6,7 +6,7 @@ import 'react-virtualized-select/styles.css'; import '../components/css/react-virtualized@9.9.0.css'; import '../components/css/Dropdown.css'; -import {propTypes, defaultProps} from '../components/Dropdown.react'; +import {propTypes} from '../components/Dropdown.react'; import {sanitizeOptions} from '../utils/optionTypes'; import isEqual from 'react-fast-compare'; @@ -168,6 +168,5 @@ const Dropdown = props => { }; Dropdown.propTypes = propTypes; -Dropdown.defaultProps = defaultProps; export default Dropdown; diff --git a/dash/development/_py_prop_typing.py b/dash/development/_py_prop_typing.py index f0bf432658..3ace0edd4a 100644 --- a/dash/development/_py_prop_typing.py +++ b/dash/development/_py_prop_typing.py @@ -120,6 +120,10 @@ def generate_enum(type_info, *_): def get_prop_typing( type_name: str, component_name: str, prop_name: str, type_info, namespace=None ): + if prop_name == "id": + # Id is always the same either a string or a dict for pattern matching. + return "typing.Union[str, dict]" + if namespace: # Only check the namespace once special = ( @@ -141,7 +145,38 @@ def generate_plotly_figure(*_): return "typing.Union[Figure, dict]" -special_cases = {"dash_core_components": {"Graph": {"figure": generate_plotly_figure}}} +def generate_datetime_prop(component, array=False): + if "import datetime" not in custom_imports["dash_core_components"][component]: + custom_imports["dash_core_components"][component].append("import datetime") + + def generator(*_): + datetime_type = "typing.Union[str, datetime.datetime]" + if array: + datetime_type = f"typing.Sequence[{datetime_type}]" + return datetime_type + + return generator + + +special_cases = { + "dash_core_components": { + "Graph": {"figure": generate_plotly_figure}, + "DatePickerRange": { + "start_date": generate_datetime_prop("DatePickerRange"), + "end_date": generate_datetime_prop("DatePickerRange"), + "min_date_allowed": generate_datetime_prop("DatePickerRange"), + "max_date_allowed": generate_datetime_prop("DatePickerRange"), + "disabled_days": generate_datetime_prop("DatePickerRange", True), + }, + "DatePickerSingle": { + "date": generate_datetime_prop("DatePickerSingle"), + "min_date_allowed": generate_datetime_prop("DatePickerSingle"), + "max_date_allowed": generate_datetime_prop("DatePickerSingle"), + "disabled_days": generate_datetime_prop("DatePickerSingle", True), + "initial_visible_month": generate_datetime_prop("DatePickerSingle"), + }, + } +} PROP_TYPING = { diff --git a/tests/unit/development/metadata_test.py b/tests/unit/development/metadata_test.py index 78ea54959e..72b8e40414 100644 --- a/tests/unit/development/metadata_test.py +++ b/tests/unit/development/metadata_test.py @@ -154,7 +154,7 @@ def __init__( optionalAny: typing.Optional[typing.Any] = None, customProp: typing.Optional[typing.Any] = None, customArrayProp: typing.Optional[typing.Sequence[typing.Any]] = None, - id: typing.Optional[str] = None, + id: typing.Optional[typing.Union[str, dict]] = None, **kwargs ): self._prop_names = ['children', 'id', 'aria-*', 'customArrayProp', 'customProp', 'data-*', 'in', 'optionalAny', 'optionalArray', 'optionalArrayOf', 'optionalBool', 'optionalElement', 'optionalEnum', 'optionalNode', 'optionalNumber', 'optionalObject', 'optionalObjectOf', 'optionalObjectWithExactAndNestedDescription', 'optionalObjectWithShapeAndNestedDescription', 'optionalString', 'optionalUnion']