Title: Confusing error message when attempting to pass a newtype as a match pattern · Issue #100530 · python/cpython · GitHub
Open Graph Title: Confusing error message when attempting to pass a newtype as a match pattern · Issue #100530 · python/cpython
X Title: Confusing error message when attempting to pass a newtype as a match pattern · Issue #100530 · python/cpython
Description: from typing import NewType T = NewType('T', str) match 'test': case T(): ... fails with: Traceback (most recent call last): File "/tmp/foo.py", line 6, in
Open Graph Description: from typing import NewType T = NewType('T', str) match 'test': case T(): ... fails with: Traceback (most recent call last): File "/tmp/foo.py", line 6, in
X Description: from typing import NewType T = NewType('T', str) match 'test': case T(): ... fails with: Traceback (most recent call last): File "/tmp/foo.py", line 6, in <module> c...
Opengraph URL: https://github.com/python/cpython/issues/100530
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Confusing error message when attempting to pass a newtype as a match pattern","articleBody":"```python\r\nfrom typing import NewType\r\n\r\nT = NewType('T', str)\r\n\r\nmatch 'test':\r\n case T(): ...\r\n```\r\n\r\nfails with:\r\n\r\n```\r\nTraceback (most recent call last):\r\n File \"/tmp/foo.py\", line 6, in \u003cmodule\u003e\r\n case T(): ...\r\n ^^^\r\nTypeError: called match pattern must be a type\r\n```\r\n\r\nThe error message is confusing because `T` is a type. The error message should probably say `class` instead of `type`, since [as per the specification](https://peps.python.org/pep-0634/#class-patterns) it's a class pattern.\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-103576\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/not-my-profile","@type":"Person","name":"not-my-profile"},"datePublished":"2022-12-26T07:02:28.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/100530/cpython/issues/100530"}
| 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:c96420b9-8856-06b1-ac4e-fd0c86f0657b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C1C6:1851F5:619B82:84B9FE:6969DC42 |
| html-safe-nonce | 037cd50eaa19305ab1ed2f2fb5e089a77720559bd5a08ba03f9b87e13ca92ad9 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMUM2OjE4NTFGNTo2MTlCODI6ODRCOUZFOjY5NjlEQzQyIiwidmlzaXRvcl9pZCI6IjY3NzY5NzA1NDY3MDEyNjE4OTAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 6ad2721cb36026354c740b32d1bc31beb4339be3b7f774394dac2ab4ef6bf54c |
| hovercard-subject-tag | issue:1510675601 |
| 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/100530/issue_layout |
| twitter:image | https://opengraph.githubassets.com/4b40d6e4b8a98135dc3a9672f1a275201b32f52dcbf357c06865b5d9a12f6f19/python/cpython/issues/100530 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/4b40d6e4b8a98135dc3a9672f1a275201b32f52dcbf357c06865b5d9a12f6f19/python/cpython/issues/100530 |
| og:image:alt | from typing import NewType T = NewType('T', str) match 'test': case T(): ... fails with: Traceback (most recent call last): File "/tmp/foo.py", line 6, in |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | not-my-profile |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7b32f1c7c4549428ee399213e8345494fc55b5637195d3fc5f493657579235e8 |
| 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 | bdde15ad1b403e23b08bbd89b53fbe6bdf688cad |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width