Title: runtime checkable protocols potential raising error with custom getattribute · Issue #105134 · python/cpython · GitHub
Open Graph Title: runtime checkable protocols potential raising error with custom getattribute · Issue #105134 · python/cpython
X Title: runtime checkable protocols potential raising error with custom getattribute · Issue #105134 · python/cpython
Description: Bug report I'm unsure if this is more tensorflow bug or python bug but it does trace to this pr and error message traces to cpython source. I've also commented on issue in tensorflow side here. # typing 3.9/3.10 produces no error, typing...
Open Graph Description: Bug report I'm unsure if this is more tensorflow bug or python bug but it does trace to this pr and error message traces to cpython source. I've also commented on issue in tensorflow side here. # t...
X Description: Bug report I'm unsure if this is more tensorflow bug or python bug but it does trace to this pr and error message traces to cpython source. I've also commented on issue in tensorflow side h...
Opengraph URL: https://github.com/python/cpython/issues/105134
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"runtime checkable protocols potential raising error with custom getattribute","articleBody":"# Bug report\r\nI'm unsure if this is more tensorflow bug or python bug but it does trace to this [pr](https://github.com/python/cpython/pull/103034) and error message traces to cpython source. I've also commented on issue in tensorflow side [here](https://github.com/tensorflow/tensorflow/issues/60687).\r\n\r\n```python\r\n# typing 3.9/3.10 produces no error, typing_extensions will trigger it.\r\nfrom typing_extensions import Protocol, runtime_checkable\r\n\r\nfrom tensorflow.python.trackable.data_structures import _DictWrapper\r\n\r\n\r\n@runtime_checkable\r\nclass Foo(Protocol):\r\n def bar(self) -\u003e None:\r\n ...\r\n\r\n\r\nisinstance(_DictWrapper(), Foo)\r\n```\r\n\r\nWith typing extensions an error message is produced of,\r\n\r\n```python\r\nTraceback (most recent call last):\r\n File \"/Users/pa-loaner/Snapchat/Dev/training-platform/scratch/runtime_protocol_custom_dict.py\", line 12, in \u003cmodule\u003e\r\n isinstance(_DictWrapper(), Foo)\r\n File \"/Users/pa-loaner/Snapchat/Dev/.venvs/tf212/lib/python3.9/site-packages/typing_extensions.py\", line 604, in __instancecheck__\r\n val = inspect.getattr_static(instance, attr)\r\n File \"/Users/pa-loaner/.pyenv/versions/3.9.16/lib/python3.9/inspect.py\", line 1711, in getattr_static\r\n instance_result = _check_instance(obj, attr)\r\n File \"/Users/pa-loaner/.pyenv/versions/3.9.16/lib/python3.9/inspect.py\", line 1654, in _check_instance\r\n instance_dict = object.__getattribute__(obj, \"__dict__\")\r\nTypeError: this __dict__ descriptor does not support '_DictWrapper' objects\r\n```\r\n# Your environment\r\n\r\nI've tested on cpython 3.9.16 and 3.10.10 where using typing works. I'd suspect 3.11 will work as well. Using typing_extensions 4.6 triggers error with inspect.getattr_static usage. Reported here instead of typing extensions as adding getattr static there was backport from here. I'd expect this to reproduce on 3.12 although installing tf on 3.12 is likely tricky and easier to test with typing extensions. The _DictWrapper class is [here](https://github.com/tensorflow/tensorflow/blob/f8066222ad6b2edbf1ee359fda66f2b43473dbe7/tensorflow/python/trackable/data_structures.py#L782) and is like a subclass of `__dict__` with a custom getattribute to do some extra tracking of elements.\r\n\r\nI used latest version of tensorflow (2.12). The underlying error message comes from this [line](https://github.com/python/cpython/blob/f90d3f68db720bd6d0deda8cc0030339ccd43858/Objects/typeobject.c#L2871). As this can be triggered in attribute access unsure whether it should be TypeError vs AttributeError. If it was attribute error getattr static would catch it and be fine. If it needs to be type error then it's unclear to me whether tensorflow class is breaking some assumption or if getattr static should also catch type errors [here](https://github.com/python/cpython/blob/f90d3f68db720bd6d0deda8cc0030339ccd43858/Lib/inspect.py#L1794). In particular it's interesting that `object.__getattribute__` can raise TypeError and inspect.getattr_static can fail.\r\n\r\nI'll try to look tomorrow if I can make a more self contained example that doesn't require tensorflow.","author":{"url":"https://github.com/hmc-cs-mdrissi","@type":"Person","name":"hmc-cs-mdrissi"},"datePublished":"2023-05-31T07:33:44.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":12},"url":"https://github.com/105134/cpython/issues/105134"}
| 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:c3c5ead7-9c40-e954-b6b3-c70b1d8cd65a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 88BE:18B65E:404500:56F76E:6969D5F6 |
| html-safe-nonce | bcda7431b73fb9c4c6738b7de14e133469a08fdd0d21e8efc0a1e6dc6e58fea8 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4OEJFOjE4QjY1RTo0MDQ1MDA6NTZGNzZFOjY5NjlENUY2IiwidmlzaXRvcl9pZCI6IjQ3MjY4ODA4MzEyMzU4MDY3MTAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 2c1889ffb43c641495d58d01d25e7e944efc9d219e9b384514121d12e6f99feb |
| hovercard-subject-tag | issue:1733567623 |
| 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/cpython/105134/issue_layout |
| twitter:image | https://opengraph.githubassets.com/857e08b7619a4262341d769abfe1a5b8d96da4a472c600d1974ccb516b61f24a/python/cpython/issues/105134 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/857e08b7619a4262341d769abfe1a5b8d96da4a472c600d1974ccb516b61f24a/python/cpython/issues/105134 |
| og:image:alt | Bug report I'm unsure if this is more tensorflow bug or python bug but it does trace to this pr and error message traces to cpython source. I've also commented on issue in tensorflow side here. # t... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | hmc-cs-mdrissi |
| hostname | github.com |
| expected-hostname | github.com |
| None | acedec8b5f975d9e3d494ddd8f949b0b8a0de59d393901e26f73df9dcba80056 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| 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 | 83c08c21cdda978090dc44364b71aa5bc6dcea79 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width