GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix datetime.combine inference when tzinfo is omitted by carljm · Pull Request #16811 · python/typeshed

Conversation

@carljm

@carljm carljm commented Nov 15, 2026

Copy link
Copy Markdown
Member

Time objects may carry a timezone, and typeshed currently doesn't model the distinction between a timezone-aware vs timezone-naive time.

If a date is combined with a timezone-aware time using datetime.combine, the resulting datetime will have the same timezone. So it is incorrect for the overloads for datetime.combine to claim that combining a date and a time (with no explicit timezone in the combine call) necessarily returns a naive datetime.

We choose datetime[tzinfo] | datetime[None] because invariance of datetime makes this a more flexible type, compared to datetime[tzinfo | None]. This parallels the existing annotation of datetime.fromisoformat().

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@carljm
Fix datetime.combine inference when tzinfo is omitted
6114a07
@github-actions

github-actions Bot commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

core (https://github.com/home-assistant/core)
+ homeassistant/components/hassio/auto_update.py:62: error: Need type annotation for "length"  [var-annotated]
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@carljm carljm mentioned this pull request Nov 15, 2026
[ty] Sync vendored typeshed stubs astral-sh/ruff#30443
Open
srittau
srittau approved these changes Nov 15, 2026
View reviewed changes
@srittau
srittau merged commit 1084116 into python:main Nov 15, 2026
88 checks passed

Uh oh!

There was an error while loading. Please reload this page.

bschnurr added a commit to bschnurr/pyright that referenced this pull request Nov 16, 2026
@bschnurr
Defer generic datetime stubs to preserve subclass behavior
6fa6059
Category A: python/typeshed#11844 (6e76a91ed3fc9a2c41b46ac6c3ae1673d0a3c2a1) loses datetime subclass identity and incorrectly infers an omitted combine timezone as None. python/typeshed#16811 fixes combine, but subclass preservation remains unresolved.

Retain the exact pre-PR datetime stub and original OverloadCall1 reveal rather than carrying an incomplete generic migration. Add focused regression coverage for constructors, factories, combine timezone forms, and invalid arguments. Full suite: 3731 tests passed; lint and typecheck passed.

Co-authored-by: Copilot <[email protected]>
@bschnurr bschnurr mentioned this pull request Nov 16, 2026
Update typeshed to 0abbaf725bf8439af222272e14326037fa5d4b2b microsoft/pyright#11996
Merged
bschnurr added a commit to microsoft/pyright that referenced this pull request Nov 16, 2026
@bschnurr
Update typeshed to 0abbaf725bf8439af222272e14326037fa5d4b2b (#11996)
3fa4803
* Update typeshed to 0abbaf725bf8439af222272e14326037fa5d4b2b

Co-authored-by: Copilot <[email protected]>

* Adjust datetime reveal for generic typeshed annotation

Typeshed made datetime generic over tzinfo in python/typeshed#11844 (6e76a91ed3fc9a2c41b46ac6c3ae1673d0a3c2a1). The existing unparameterized annotation now displays as datetime[Any].

Co-authored-by: Copilot <[email protected]>

* Defer generic datetime stubs to preserve subclass behavior

Category A: python/typeshed#11844 (6e76a91ed3fc9a2c41b46ac6c3ae1673d0a3c2a1) loses datetime subclass identity and incorrectly infers an omitted combine timezone as None. python/typeshed#16811 fixes combine, but subclass preservation remains unresolved.

Retain the exact pre-PR datetime stub and original OverloadCall1 reveal rather than carrying an incomplete generic migration. Add focused regression coverage for constructors, factories, combine timezone forms, and invalid arguments. Full suite: 3731 tests passed; lint and typecheck passed.

Co-authored-by: Copilot <[email protected]>

---------

Co-authored-by: Copilot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@srittau srittau srittau approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@carljm @srittau
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.