Conversation
Contributor
|
Diff from mypy_primer, showing the effect of this PR on open source code: core (https://github.com/home-assistant/core)
+ homeassistant/data_entry_flow.py:653: error: Unused "type: ignore" comment [unused-ignore]
|
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.
In
mypy/checkexpr.py, updateExpressionChecker.method_fullnameto resolve a TypeVar's proper upper bound for TypedDict method lookup, allowing the existing fallback owner lookup to identifytyping.Mapping.get; keep the receiver's original type intact elsewhere and leave unrelated bound kinds unchanged. Inmypy/plugins/default.py, normalize the receiver locally in bothtyped_dict_get_signature_callbackandtyped_dict_get_callbackby inspecting a TypeVar's proper upper bound, then use that local TypedDict type for field lookup, required keys, and closedness. Reuse the existing signature-context and return-type algorithms so empty collection defaults and nested TypedDict defaults work without changing the plugin context contract or adding a helper used only by tests. Calling.geton a TypeVar bounded by a TypedDict loses the field type and producesobject, while indexing and direct TypedDict.getpreserve the field type. The original example uses a requiredlist[str]field, and the September 2026 confirmation reproduces the issue with both legacy TypeVar declarations and Python 3.12 type parameter syntax. Current direct TypedDict behavior returns the field type alone for required keys, so the original expectation of an unconditional union withNoneis outdated. The fix should match current direct-receiver behavior, including optional keys, explicit defaults, and contextual inference. Requiredlist[str]key: legacy bounded TypeVar.getreturnslist[str], matching direct.getand indexing, with and without an explicit default. Returning the original argument as T still preserves generic identity; Optional key (total=Falseand a mixed Required/NotRequired TypedDict): omitted default returns value-or-None; an unrelated explicit default returns the appropriate union; a default of the field type collapses the union.Fixes #16872