Title: Convert more examples to doctests in `typing` module · Issue #112194 · python/cpython · GitHub
Open Graph Title: Convert more examples to doctests in `typing` module · Issue #112194 · python/cpython
X Title: Convert more examples to doctests in `typing` module · Issue #112194 · python/cpython
Description: Feature or enhancement There are multiple examples that are very similar to doctests, but are not doctests. I propose adding >>> and ... to them, so these examples would be checked during tests (since now we have this feature). There are...
Open Graph Description: Feature or enhancement There are multiple examples that are very similar to doctests, but are not doctests. I propose adding >>> and ... to them, so these examples would be checked during tests (si...
X Description: Feature or enhancement There are multiple examples that are very similar to doctests, but are not doctests. I propose adding >>> and ... to them, so these examples would be checked during ...
Opengraph URL: https://github.com/python/cpython/issues/112194
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Convert more examples to doctests in `typing` module","articleBody":"# Feature or enhancement\r\n\r\nThere are multiple examples that are very similar to doctests, but are not doctests.\r\nI propose adding `\u003e\u003e\u003e` and `...` to them, so these examples would be checked during tests (since now we have this feature).\r\n\r\nThere are some easy ones, where just adding `\u003e\u003e\u003e` (and some imports are enough).\r\nThere are also some more complex ones, where some new types / vars are needed, but I don't think it is worth doing, because it will increase the complexity of these examples.\r\n\r\nExamples:\r\n- https://github.com/python/cpython/blob/0ee2d77331f2362fcaab20cc678530b18e467e3c/Lib/typing.py#L207-L217\r\n- https://github.com/python/cpython/blob/0ee2d77331f2362fcaab20cc678530b18e467e3c/Lib/typing.py#L252-L259\r\n- https://github.com/python/cpython/blob/0ee2d77331f2362fcaab20cc678530b18e467e3c/Lib/typing.py#L672-L686\r\n- https://github.com/python/cpython/blob/0ee2d77331f2362fcaab20cc678530b18e467e3c/Lib/typing.py#L2239-L2255\r\n- https://github.com/python/cpython/blob/0ee2d77331f2362fcaab20cc678530b18e467e3c/Lib/typing.py#L2268-L2280\r\n- https://github.com/python/cpython/blob/0ee2d77331f2362fcaab20cc678530b18e467e3c/Lib/typing.py#L2293-L2304\r\n- https://github.com/python/cpython/blob/0ee2d77331f2362fcaab20cc678530b18e467e3c/Lib/typing.py#L2899-L2909\r\n\r\nThis actually reveals a bug:\r\n\r\nhttps://github.com/python/cpython/blob/0ee2d77331f2362fcaab20cc678530b18e467e3c/Lib/typing.py#L207-L219\r\n\r\n`assert collections.abc.Callable[ParamSpec, str].__args__ == (ParamSpec, str)` example is invalid:\r\n\r\n```\r\nFile \"/Users/sobolev/Desktop/cpython2/Lib/typing.py\", line 218, in typing._should_unflatten_callable_args\r\nFailed example:\r\n assert collections.abc.Callable[ParamSpec, str].__args__ == (ParamSpec, str)\r\nException raised:\r\n Traceback (most recent call last):\r\n File \"/Users/sobolev/Desktop/cpython2/Lib/doctest.py\", line 1374, in __run\r\n exec(compile(example.source, filename, \"single\",\r\n File \"\u003cdoctest typing._should_unflatten_callable_args[2]\u003e\", line 1, in \u003cmodule\u003e\r\n assert collections.abc.Callable[ParamSpec, str].__args__ == (ParamSpec, str)\r\n ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^\r\n File \"/Users/sobolev/Desktop/cpython2/Lib/_collections_abc.py\", line 477, in __new__\r\n raise TypeError(f\"Expected a list of types, an ellipsis, \"\r\n TypeError: Expected a list of types, an ellipsis, ParamSpec, or Concatenate. Got \u003cclass 'typing.ParamSpec'\u003e\r\n```\r\n\r\n\u003c!-- gh-linked-prs --\u003e\r\n### Linked PRs\r\n* gh-112195\r\n* gh-112208\n* gh-112209\n\u003c!-- /gh-linked-prs --\u003e\r\n","author":{"url":"https://github.com/sobolevn","@type":"Person","name":"sobolevn"},"datePublished":"2023-11-17T09:49:39.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/112194/cpython/issues/112194"}
| 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:1c68c2f3-077a-ba8a-81f8-e53812802b33 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B8BA:74E61:1CD0A0F:28881C6:696A56EB |
| html-safe-nonce | c31becbdc3bf10ff4c937e1ac7cc0854bdd62f0cfa3aa5384bf7b830d2510bf3 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCOEJBOjc0RTYxOjFDRDBBMEY6Mjg4ODFDNjo2OTZBNTZFQiIsInZpc2l0b3JfaWQiOiI4NDM2MjQwMTEyNDk5MTg1Mzg3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | e170f6e4f44f1e4d3f0984c809398df685abdf44853a7f4ff0f21e1c923f9939 |
| hovercard-subject-tag | issue:1998709072 |
| 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/112194/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d4f2e0b757451f49127ab6f5cfdce156e2139563adf0079298f109b1815ef3ad/python/cpython/issues/112194 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d4f2e0b757451f49127ab6f5cfdce156e2139563adf0079298f109b1815ef3ad/python/cpython/issues/112194 |
| og:image:alt | Feature or enhancement There are multiple examples that are very similar to doctests, but are not doctests. I propose adding >>> and ... to them, so these examples would be checked during tests (si... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | sobolevn |
| hostname | github.com |
| expected-hostname | github.com |
| None | 3f871c8e07f0ae1886fa8dac284166d28b09ad5bada6476fc10b674e489788ef |
| 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 | 63c426b30d262aba269ef14c40e3c817b384cd61 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width