Title: typing.MutableMapping not a drop-in replacement for collections.abc.MutableMapping · Issue #203 · python/typing · GitHub
Open Graph Title: typing.MutableMapping not a drop-in replacement for collections.abc.MutableMapping · Issue #203 · python/typing
X Title: typing.MutableMapping not a drop-in replacement for collections.abc.MutableMapping · Issue #203 · python/typing
Description: The only difference between typing.MutableMapping and its collections.abc counterpart is supposed to be the support for generic type parameters. However, it looks like it's also missing some other methods: import collections.abc import t...
Open Graph Description: The only difference between typing.MutableMapping and its collections.abc counterpart is supposed to be the support for generic type parameters. However, it looks like it's also missing some other ...
X Description: The only difference between typing.MutableMapping and its collections.abc counterpart is supposed to be the support for generic type parameters. However, it looks like it's also missing some ot...
Opengraph URL: https://github.com/python/typing/issues/203
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"typing.MutableMapping not a drop-in replacement for collections.abc.MutableMapping","articleBody":"The only difference between `typing.MutableMapping` and its `collections.abc` counterpart is supposed to be the support for generic type parameters. However, it looks like it's also missing some other methods:\n\n```\nimport collections.abc\nimport typing\n\ndef define_user_dict(base_class):\n class MyUserDict(base_class):\n def __getitem__(self, k):\n return None\n def __setitem__(self, k, v):\n pass\n def __delitem__(self, k):\n pass\n def __iter__(self):\n return iter(())\n def __len__(self):\n return 0\n return MyUserDict\n\nUserDict1 = define_user_dict(collections.abc.MutableMapping)\nUserDict2 = define_user_dict(typing.MutableMapping[str, str])\n\nUserDict1().update() # this one works\nUserDict2().update() # this one fails\n```\n\n```\n$ python3.5 /tmp/mappingtest.py\nTraceback (most recent call last):\n File \"/tmp/mappingtest.py\", line 22, in \u003cmodule>\n UserDict2().update()\nAttributeError: 'MyUserDict' object has no attribute 'update'\n```\n\nTested on python 3.5.1, and on python 3.4 with `typing` 3.5.1.0 installed.\n\nIs changing my base class from `collections.abc.MutableMapping` to `typing.MutableMapping` the right way to tell the type checker what types my user dict will work with? Should I be using both base classes together? Is there a way to tell the type checker that `MyUserDict` is a `typing.MutableMapping[str, str]` while keeping `collections.abc.MutableMapping` as the runtime base class?\n\nAdditionally, `isinstance()` checking is funky: `isinstance(dict(), UserDict2)` returns true, so I can't use `isinstance()` to distinguish my dict type from any other.\n","author":{"url":"https://github.com/bdarnell","@type":"Person","name":"bdarnell"},"datePublished":"2016-04-17T18:26:14Z","url":"https://github.com/python/typing/issues/203"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:aac2ef10-3aa0-b14b-fa94-000d18b1d9f2 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9120:1AAA8E:1A231:224F7:6B001747 |
| html-safe-nonce | fa1f5fd06d1bf9f31896a0fc7edc2ded9e131b51420ee1f9828fde5c47a6d574 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MTIwOjFBQUE4RToxQTIzMToyMjRGNzo2QjAwMTc0NyIsInZpc2l0b3JfaWQiOiIzMzM4MjgyNjcyODQ4OTAxOTU5IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 355c6606b7be260f729201d6cf4becbe000083dc7338f2b77affa26df30fd3f1 |
| hovercard-subject-tag | issue:148979178 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/typing/203/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7834bc163718c03cfc11269f16721d23d883a2df4a869d716fc017dab9b07521/python/typing/issues/203 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7834bc163718c03cfc11269f16721d23d883a2df4a869d716fc017dab9b07521/python/typing/issues/203 |
| og:image:alt | The only difference between typing.MutableMapping and its collections.abc counterpart is supposed to be the support for generic type parameters. However, it looks like it's also missing some other ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | bdarnell |
| hostname | github.com |
| expected-hostname | github.com |
| None | a2dd2291b1b13cc9c06f27ec92fa3dbaf34116fc24c9347b8539db61884c59f4 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/typing git https://github.com/python/typing.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 24604008 |
| octolytics-dimension-repository_nwo | python/typing |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 24604008 |
| octolytics-dimension-repository_network_root_nwo | python/typing |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 70121d4e855ee0bb7b75cf15d061d91f8863c0f8 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width