Uh oh!
There was an error while loading. Please reload this page.
Introduce Mapping-like protocols - #4325
Conversation
typing.Mapping is not a protocol, which has caused problems in the past. (E.g. python#3569, see also python#3576.) This introduces a few narrow protocols to _typeshed.pyi that can be used in place of Mapping. Not all uses of Mapping can be replaced. For example, cgi.FieldStorage explictly checks whether the supplied headers argument is a Mapping instance.
| def items(self) -> AbstractSet[Tuple[_KT_co, _VT_co]]: ... | ||
| class SupportsGetItem(Container[_KT_contra], Protocol[_KT_contra, _VT_co]): | ||
| def __getitem__(self, __k: _KT_contra) -> _VT_co: ... |
There was a problem hiding this comment.
See python/typing#273 and #550 for some previous discussion on the variance of Mapping (not directly relevant here).
For example, |
srittau
commented
Aug 2, 2020
If the implementation changes, the stubs need to change as well. We tend to follow implementation, not documentation in typeshed. |
torstenrudolf
commented
Oct 20, 2020
is there a way I can use the |
hauntsaninja
commented
Oct 20, 2020
Look at the comment at the top of the file :-) |
typing.Mapping is not a protocol, which has caused problems in the past.
(E.g. #3569, see also #3576.) This
introduces a few narrow protocols to _typeshed.pyi that can be used in
place of Mapping.
Not all uses of Mapping can be replaced. For example, cgi.FieldStorage
explictly checks whether the supplied headers argument is a Mapping
instance.