Skip to content

datetime generic issues #16990

Backlog
Backlog

Description

@DetachHead

the recent change to datetime.__sub__ causes issues with pyrefly. see pyrefly-org/pyrefly#5847

i'm pretty sure this can be fixed on pyrefly's side, but i'm also opening an issue here because i think there are also improvements that can be made on the typeshed side:

  • is there a reason why the default value for _TzInfoT is Any? can it be tzinfo | None or just None instead?
  • the # type: ignore comments on the datetime.__sub__ overload have no comments explaining why they're there (or even what type checker they're for). this is probably a broader issue with typeshed in general, but i think all # type: ignore comments need an accompanying comment explaining why it's there and/or a link to a relevant issue

Activity

  1. srittau commented on Dec 4, 2026

    @srittau
    Collaborator

    I don't remember exactly why Any was used as default. Possibly to reduce the churn or number of new false positives, possibly because there were problems with tzinfo | Any. But I agree that the latter would be a more desirable default. An exploratory PR would be welcome.

    I agree about the # type: ignore. We also probably have many unnecessary ignores for some old type checker bugs. But generally # type: ignores are for mypy, since we tend to use type-checker specific ignores, and mypy didn't support them until recently. In this case, they are definitely for mypy, since we include the error code.

    In this case the overloads are necessary because the datetime.__sub__ violates the LSP and does some shenanigans that mypy supports, but unnecessarily complains about.

  2. srittau commented on Dec 4, 2026

    @srittau
    Collaborator

    @xixi-box opened #16993, which has rather extensive primer output for the default change. Hopefully, we'll be able to change the default at some point in the future if people start to explicitly annotation their datetimes.

  3. kinto0 commented on Dec 4, 2026

    @kinto0

    let's see how #17023 looks as an alternative. it looks a lot better on pyrefly/ty so far

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions