Skip to content

component typing id as dict and datetime for Date pickers in Dash 3.0rc1 #3141

Closed

Description

@tlauli

Hi, I tried to update to dash 3.0rc1, and what I noticed is that some typehints are too strict. What I found:

  • ids are typed as typing.Optional[str], omitting dict ids
  • dates in datepickers are typed as typing.Optional[str], but we use datetime.dates without problem, not sure if dates working is intended or just a coincidence though
    There are possibly others, this is what I found in our codebase.

Activity

  1. self-assigned this
    on Jan 29, 2025
  2. added
    dash-3.0Going in dash-3.0 release.
    P1needed for current cycle
    on Jan 29, 2025
  3. changed the title [-][BUG] Dash 3.0rc1 too strict typehints[/-] [+][BUG] Dash 3.0rc1, component typing id as dict and datetime for Date pickers[/+] on Feb 6, 2025
  4. changed the title [-][BUG] Dash 3.0rc1, component typing id as dict and datetime for Date pickers[/-] [+]component typing id as dict and datetime for Date pickers in Dash 3.0rc1[/+] on Feb 13, 2025
  5. tlauli commented on Mar 18, 2025

    @tlauli
    ContributorAuthor

    @T4rk1n Hi, I see the the types were expanded to allow datetime.datetime for dates in datepicker, but it should be datetime.date.

  6. T4rk1n commented on Mar 18, 2025

    @T4rk1n
    Contributor

    @T4rk1n Hi, I see the the types were expanded to allow datetime.datetime for dates in datepicker, but it should be datetime.date.

    My bad, I tested with datetime.datetime.now() and assumed it was the same, it should be union of both.

  7. reopened this on Mar 18, 2025
  8. tlauli commented on Mar 18, 2025

    @tlauli
    ContributorAuthor

    I think it would be better to allow datetime.date only. Otherwise it is possible to init the datepicker with something that has time different from midnight (this still correctly sets the date in ui), and if the user does not change the date, then the time is read back into callbacks, which can be surprising in my opinion. In the attached example, 2025-03-18T14:17:32.244956 is shown, instead of just the date.

    layout = html.Div(
        [
            dcc.DatePickerSingle(id="datepicker", date=datetime.datetime.now()),
            html.Div(id="output"),
        ],
    )
    
    
    @callback(
        Output("output", "children"),
        Input("datepicker", "date"),
    )
    def xxx(date: str | None) -> str:
        return date
    
    
  9. T4rk1n commented on Mar 18, 2025

    @T4rk1n
    Contributor

    The base class is datetime.date, it handle both.

  10. tlauli commented on Mar 18, 2025

    @tlauli
    ContributorAuthor

    Oh, of course. Then both date and datetime is fine. It could maybe be nice to throw away the time part in the component if present, but that is out of the scope of this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P1needed for current cycledash-3.0Going in dash-3.0 release.

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions