-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Disallow Mapping
as argument type?
#3576
Comments
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.
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.
Rather than disallowing Relatedly, if we had python/mypy#2922, I guess |
I think it's hard to make |
Indeed. We looked into this and found it would be very difficult. I strongly recommend just inheriting from Mapping over coming up with yet another duck typing protocol. FWIW mypy probably will never support .register(). |
We have Possibly we could look into adding lints to detect bad uses of |
This came up in #3569. See also the later comments in python/typing#11 for background.
Mapping
is not a protocol (as opposed to most other typing ABCs). This mean code like the following will not work:Deriving
MyMap
fromMapping[str, int]
works, though. I suggest we don't allow new submissions to useMapping
as argument type and work towards removing existing uses. Instead they should use a custom protocol, which can also be narrower thanMapping
.The text was updated successfully, but these errors were encountered: