Title: Untested code in `typing.py` · Issue #105834 · python/cpython · GitHub
Open Graph Title: Untested code in `typing.py` · Issue #105834 · python/cpython
X Title: Untested code in `typing.py` · Issue #105834 · python/cpython
Description: Bug report If you apply this diff to typing.py, all tests continue to pass: diff --git a/Lib/typing.py b/Lib/typing.py index 1dd9398344..98e19644a2 100644 --- a/Lib/typing.py +++ b/Lib/typing.py @@ -1931,6 +1931,7 @@ def _proto_hook(othe...
Open Graph Description: Bug report If you apply this diff to typing.py, all tests continue to pass: diff --git a/Lib/typing.py b/Lib/typing.py index 1dd9398344..98e19644a2 100644 --- a/Lib/typing.py +++ b/Lib/typing.py @@...
X Description: Bug report If you apply this diff to typing.py, all tests continue to pass: diff --git a/Lib/typing.py b/Lib/typing.py index 1dd9398344..98e19644a2 100644 --- a/Lib/typing.py +++ b/Lib/typing.py @@...
Opengraph URL: https://github.com/python/cpython/issues/105834
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Untested code in `typing.py`","articleBody":"# Bug report\r\n\r\nIf you apply this diff to `typing.py`, all tests continue to pass:\r\n\r\n```diff\r\ndiff --git a/Lib/typing.py b/Lib/typing.py\r\nindex 1dd9398344..98e19644a2 100644\r\n--- a/Lib/typing.py\r\n+++ b/Lib/typing.py\r\n@@ -1931,6 +1931,7 @@ def _proto_hook(other):\r\n if (isinstance(annotations, collections.abc.Mapping) and\r\n attr in annotations and\r\n issubclass(other, Generic) and getattr(other, '_is_protocol', False)):\r\n+ 1/0\r\n break\r\n```\r\n\r\nThe `break` on line 1934 here is unreachable; thus, this whole block of code is pointless:\r\n\r\nhttps://github.com/python/cpython/blob/3af2dc7588614c65e9d1178ad9b4a11a19c14dde/Lib/typing.py#L1929-L1934\r\n\r\nI think we can say for sure that the `break` here is unreachable. This is the `__subclasshook__` method that is monkey-patched onto all subclasses of `typing.Protocol` that do not define their own `__subclasshook__` methods. This block of code in the `__subclasshook__` method is inspecting the `__annotations__` dictionary of `other` to see if it can find any protocol members in that dictionary. _But_ we know that there can't be any protocol members in the `__annotations__` dictionary, because if there were, that would make `other` a protocol with at least one non-callable member. If it's a protocol that has at least one non-callable member, the `__subclasshook__` method is never called at all during `isinstance()` or `issubclass()` checks, because we raise `TypeError` in `_ProtocolMeta.__subclasscheck__`, short-circuiting the call to `abc.ABCMeta.__subclasscheck__` that would call `Protocol.__subclasshook__`:\r\n\r\nhttps://github.com/python/cpython/blob/3af2dc7588614c65e9d1178ad9b4a11a19c14dde/Lib/typing.py#L1828-L1831\r\n\r\nI believe that this block of code can therefore be safely deleted.\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-105835\n* gh-105859\n* gh-105860\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/AlexWaygood","@type":"Person","name":"AlexWaygood"},"datePublished":"2023-06-15T18:22:48.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/105834/cpython/issues/105834"}
| 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:c5713581-fa39-225c-5139-c8a02ab8f99c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B9F8:2A0949:430894:5E7ADA:696A0BD3 |
| html-safe-nonce | dc3842bcabd5547bfa9cbdf3489dc2227f40b2b26916637a00b5b130769d6961 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCOUY4OjJBMDk0OTo0MzA4OTQ6NUU3QURBOjY5NkEwQkQzIiwidmlzaXRvcl9pZCI6IjE5MTUzNDc2ODQxMzM0Njc3MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | c797075d66ee8fafc4663ff2e774a3f1ec28075258f8f0bbb54e36226ca79119 |
| hovercard-subject-tag | issue:1759336111 |
| 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/105834/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ab2d8b3fa842c2cb20949370d82b39036b6eb7baace4766522c50e4141bd62d4/python/cpython/issues/105834 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ab2d8b3fa842c2cb20949370d82b39036b6eb7baace4766522c50e4141bd62d4/python/cpython/issues/105834 |
| og:image:alt | Bug report If you apply this diff to typing.py, all tests continue to pass: diff --git a/Lib/typing.py b/Lib/typing.py index 1dd9398344..98e19644a2 100644 --- a/Lib/typing.py +++ b/Lib/typing.py @@... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | AlexWaygood |
| hostname | github.com |
| expected-hostname | github.com |
| None | 699227a00bbb7fe1eec276d2ae1c3a93068bc5ba483bd9dc4b2a27a8f4f2f595 |
| 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 | 7266b2d935baa1c6474b16dd9feaa5ca30607261 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width