Repository navigation
Fix datetime.combine inference when tzinfo is omitted - #16811
Merged
Merged
Conversation
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]
|
srittau
approved these changes
Nov 15, 2026
bschnurr
added a commit
to bschnurr/pyright
that referenced
this pull request
Nov 16, 2026
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 <223556219+Copilot@users.noreply.github.com>
bschnurr
added a commit
to microsoft/pyright
that referenced
this pull request
Nov 16, 2026
* Update typeshed to 0abbaf725bf8439af222272e14326037fa5d4b2b Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * 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 <223556219+Copilot@users.noreply.github.com> * 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 <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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 fordatetime.combineto claim that combining a date and a time (with no explicit timezone in thecombinecall) necessarily returns a naive datetime.We choose
datetime[tzinfo] | datetime[None]because invariance ofdatetimemakes this a more flexible type, compared todatetime[tzinfo | None]. This parallels the existing annotation ofdatetime.fromisoformat().