Skip to content

Fix dates and id typing #3142

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

Merged
merged 7 commits into from
Feb 5, 2025
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
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/).

## [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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'react-virtualized-select/styles.css';
import '../components/css/[email protected]';
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';

Expand Down Expand Up @@ -168,6 +168,5 @@ const Dropdown = props => {
};

Dropdown.propTypes = propTypes;
Dropdown.defaultProps = defaultProps;

export default Dropdown;
37 changes: 36 additions & 1 deletion dash/development/_py_prop_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand All @@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/development/metadata_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down