-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Add Protocols for mapping inside dictionary view objects #14574
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The primer output is promising. Just one note about the protocols below.
stdlib/_typeshed/__init__.pyi
Outdated
# Suitable for dictionary view objects | ||
class Viewable(Sized, Iterable[_KT_co], Protocol): ... | ||
class SupportsGetItemViewable(Viewable[_KT], SupportsGetItem[_KT, _VT_co], Protocol): ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you move these up to the other Supports*
protocols?
Also, in typeshed (or at least in the _typeshed
module) we have a slight preference for spelling out the methods supported in protocol, instead of deriving from other protocols, see for example SupportsItemAccess
above. This makes it slightly easier for users to understand what methods are needed to fulfill a protocol instead of traversing through the class hierarchy.
Diff from mypy_primer, showing the effect of this PR on open source code: zope.interface (https://github.com/zopefoundation/zope.interface)
- src/zope/interface/common/collections.py:233: error: Incompatible types in assignment (expression has type "type[ItemsView[_KT_co, _VT_co]]", base class "ISet" defined the type as "type[AbstractSet[_T_co]]") [assignment]
+ src/zope/interface/common/collections.py:233: error: Incompatible types in assignment (expression has type "type[ItemsView[_KT_co, _VT_co]]", base class "IMappingView" defined the type as "type[MappingView]") [assignment]
- src/zope/interface/common/collections.py:237: error: Incompatible types in assignment (expression has type "type[KeysView[_KT_co]]", base class "ISet" defined the type as "type[AbstractSet[_T_co]]") [assignment]
+ src/zope/interface/common/collections.py:237: error: Incompatible types in assignment (expression has type "type[KeysView[_KT_co]]", base class "IMappingView" defined the type as "type[MappingView]") [assignment]
+ src/zope/interface/common/collections.py:241: error: Incompatible types in assignment (expression has type "type[ValuesView[_VT_co]]", base class "IMappingView" defined the type as "type[MappingView]") [assignment]
static-frame (https://github.com/static-frame/static-frame)
+ static_frame/core/series_mapping.py:21: error: Unused "type: ignore" comment [unused-ignore]
+ static_frame/core/series_mapping.py:26: error: Unused "type: ignore" comment [unused-ignore]
+ static_frame/core/series_mapping.py:32: error: Unused "type: ignore" comment [unused-ignore]
ibis (https://github.com/ibis-project/ibis)
- ibis/common/collections.py:140: error: Argument 1 to "KeysView" has incompatible type "ibis.common.collections.Mapping[K, V]"; expected "typing.Mapping[K, Any]" [arg-type]
- ibis/common/collections.py:143: error: Argument 1 to "ItemsView" has incompatible type "ibis.common.collections.Mapping[K, V]"; expected "typing.Mapping[K, V]" [arg-type]
discord.py (https://github.com/Rapptz/discord.py)
- discord/ext/commands/hybrid.py:508: error: Overlap between argument names and ** TypedDict items: "name", "description" [misc]
+ discord/ext/commands/hybrid.py:508: error: Overlap between argument names and ** TypedDict items: "description", "name" [misc]
- discord/ext/commands/hybrid.py:629: error: Overlap between argument names and ** TypedDict items: "name", "description" [misc]
+ discord/ext/commands/hybrid.py:629: error: Overlap between argument names and ** TypedDict items: "description", "name" [misc]
|
Resolves #14555