Skip to content

Recommend DateType in the datetime documentation #105563

Closed

Description

@pganssle

Documentation

At the PyCon US 2023 sprints, I spent some time with @glyph, @hauntsaninja, @AlexWaygood and others trying to put together a plan to make the type stubs for datetime distinguish between naïve and aware datetimes (even if the runtime types don't reflect this). Unfortunately, we came to the conclusion that there's no way to do it in a backwards-compatible way that accounts for subclasses without the use of higher-kinded types (this is not the first time we came to that conclusion, and unfortunately in neither case did we write down the exact reason this is a problem as far as I know, so, uh... let's remember to do that next time we tilt at this particular windmill).

Some time ago, however, @glyph did come up with a set of Protocol classes that basically solves the problem for anyone who is willing to opt in to it, since that frees him from certain backwards compatibility concerns. The upshot of the conversation was that the best we can do from the CPython side is probably to add a link to DateType into the datetime documentation, presumably in the "See also" infobox, along with a recommendation that it can be used to improve type checking of naïve vs. aware datetimes.

I realized that we didn't get around to this in the sprints and we never made an issue to track the progress, so when this recently came up in this issue, it reminded me to open this issue.

CC: @abalkin

Linked PRs

Activity

  1. rakesh9541 commented on Jul 6, 2023

    @rakesh9541

    can you assign me this??

  2. AlexWaygood commented on Jul 6, 2023

    @AlexWaygood
    Member

    can you assign me this??

    Hi @rakesh9541! Unfortunately there is already an open PR to address this issue: #105946. I would be better to wait until that has been reviewed before opening another one :)

  3. added a commit that references this issue on Sep 1, 2023
  4. added 2 commits that reference this issue on Sep 1, 2023
  5. added a commit that references this issue on Sep 1, 2023
  6. added a commit that references this issue on Sep 2, 2023
  7. tigercosmos commented on Oct 29, 2023

    @tigercosmos
    Contributor

    this one should be closed?

  8. glyph commented on Oct 29, 2023

    @glyph
    Contributor

    this one should be closed?

    yep, the recommendation is definitely there in the docs now

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc direasy

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions