Widen dict_keys/dict_items isdisjoint parameter type#15976
Open
muhamedfazalps wants to merge 1 commit into
Open
Widen dict_keys/dict_items isdisjoint parameter type#15976muhamedfazalps wants to merge 1 commit into
muhamedfazalps wants to merge 1 commit into
Conversation
Change dict_keys.isdisjoint and dict_items.isdisjoint parameter types from Iterable[_KT_co]/Iterable[tuple[_KT_co, _VT_co]] to Iterable[object]. This matches the pattern used by set.isdisjoint and frozenset.isdisjoint, and fixes false positives when using TypedDict with closed=True where the key type is a union of string literals. Fixes python#15888
Contributor
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
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.
Summary
Widen the parameter type of
dict_keys.isdisjointanddict_items.isdisjointfromIterable[_KT_co]/Iterable[tuple[_KT_co, _VT_co]]toIterable[object].Fixes #15888
Motivation
The current strict type causes false positives when using
TypedDictwithclosed=Truewhere the key type is a union of string literals. When iterating over dict keys and passing them toisdisjoint, the strict type rejects valid operations:Changes
stdlib/_collections_abc.pyi: Changeddict_keys.isdisjointparameter fromIterable[_KT_co]toIterable[object]stdlib/_collections_abc.pyi: Changeddict_items.isdisjointparameter fromIterable[tuple[_KT_co, _VT_co]]toIterable[object]This matches the pattern already used by
set.isdisjointandfrozenset.isdisjoint, which acceptIterable[object].Discovered during open source research. https://buymeacoffee.com/muhamedfazalps