Title: Support Ellipsis as a type per se · Issue #684 · python/typing · GitHub
Open Graph Title: Support Ellipsis as a type per se · Issue #684 · python/typing
X Title: Support Ellipsis as a type per se · Issue #684 · python/typing
Description: Referenced from python/mypy#7818 We use an Ellipsis as an easy-to-understand, easy-to-import sentinel value to mean "everything else". But it's not possible to use fully with type checking, since mypy doesn't exclude it from a type when ...
Open Graph Description: Referenced from python/mypy#7818 We use an Ellipsis as an easy-to-understand, easy-to-import sentinel value to mean "everything else". But it's not possible to use fully with type checking, since m...
X Description: Referenced from python/mypy#7818 We use an Ellipsis as an easy-to-understand, easy-to-import sentinel value to mean "everything else". But it's not possible to use fully with type che...
Opengraph URL: https://github.com/python/typing/issues/684
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Support Ellipsis as a type per se","articleBody":"Referenced from https://github.com/python/mypy/issues/7818\r\n\r\nWe use an Ellipsis as an easy-to-understand, easy-to-import sentinel value to mean \"everything else\". \r\n\r\nBut it's not possible to use fully with type checking, since mypy doesn't exclude it from a type when it's been excluded with an `if`, as it does for `None`, or `Enum`s per https://github.com/python/typing/pull/240). I've moved the issue here since it's apparently a python typing issue rather than a mypy implementation.\r\n\r\nI've included below a MCVE of the behavior below, and here's an example of how we use it, given @gvanrossum has [already asked](https://github.com/python/mypy/issues/2180) whether it's important to use an Ellipsis:\r\n\r\n\r\n\u003cdetails>\r\n\r\nFor example, to transpose an array, these are equivalent:\r\n\r\n```python\r\n\r\nIn [1]: import xarray as xr\r\n\r\nIn [2]: ds = xr.tutorial.scatter_example_dataset()\r\n\r\nIn [3]: ds\r\nOut[3]:\r\n\u003cxarray.Dataset>\r\nDimensions: (w: 4, x: 3, y: 11, z: 4)\r\nCoordinates:\r\n * x (x) int64 0 1 2\r\n * y (y) float64 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0\r\n * z (z) int64 0 1 2 3\r\n * w (w) \u003cU5 'one' 'two' 'three' 'five'\r\nData variables:\r\n A (x, y, z, w) float64 0.02074 0.04807 -0.1059 ... -0.1809 -0.04862\r\n B (x, y, z, w) float64 0.0 0.0 0.0 0.0 ... 1.406 1.414 1.368 1.408\r\n\r\nIn [4]: ds.transpose('w','x','y','z')\r\nOut[4]:\r\n\u003cxarray.Dataset>\r\nDimensions: (w: 4, x: 3, y: 11, z: 4)\r\nCoordinates:\r\n * x (x) int64 0 1 2\r\n * y (y) float64 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0\r\n * z (z) int64 0 1 2 3\r\n * w (w) \u003cU5 'one' 'two' 'three' 'five'\r\nData variables:\r\n A (w, x, y, z) float64 0.02074 0.02074 0.02074 ... -0.03076 -0.04862\r\n B (w, x, y, z) float64 0.0 0.002074 0.004147 ... 1.403 1.405 1.408\r\n\r\n\r\nIn [5]: ds.transpose('w',...) # use an Ellipsis to indicate 'all other dimensions'\r\nOut[5]:\r\n\u003cxarray.Dataset>\r\nDimensions: (w: 4, x: 3, y: 11, z: 4)\r\nCoordinates:\r\n * x (x) int64 0 1 2\r\n * y (y) float64 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0\r\n * z (z) int64 0 1 2 3\r\n * w (w) \u003cU5 'one' 'two' 'three' 'five'\r\nData variables:\r\n A (w, x, y, z) float64 0.02074 0.02074 0.02074 ... -0.03076 -0.04862\r\n B (w, x, y, z) float64 0.0 0.002074 0.004147 ... 1.403 1.405 1.408\r\n```\r\n\r\n\u003c/details>\r\n\r\nCode example with existing mypy:\r\n\r\n```python\r\nimport builtins\r\nfrom typing import List, Union\r\n\r\n\r\ndef fun(x: Union[builtins.ellipsis, List], y: List):\r\n if x is not Ellipsis:\r\n y = x # error: Incompatible types in assignment (expression has type \"Union[ellipsis, List[Any]]\", variable has type \"List[Any]\")\r\n\r\n return y\r\n\r\n# another attempt:\r\ndef fun2(x: Union[Ellipsis, List], y: List): # error: Variable \"builtins.Ellipsis\" is not valid as a type\r\n if x is not Ellipsis:\r\n y = x\r\n\r\n return y\r\n\r\n```\r\n\r\nThank you!\r\n","author":{"url":"https://github.com/max-sixty","@type":"Person","name":"max-sixty"},"datePublished":"2019-10-30T18:36:21Z","url":"https://github.com/python/typing/issues/684"}
| 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:6ab6e24f-f8b8-a665-0451-9db4d3c8e800 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CB6C:23E2FF:108E68:169EC5:6B0063B5 |
| html-safe-nonce | 13704e9a53b9540ff72eabf5e0c914b9a84dc90a63e68ca04128127a4e9aca19 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQjZDOjIzRTJGRjoxMDhFNjg6MTY5RUM1OjZCMDA2M0I1IiwidmlzaXRvcl9pZCI6IjM2ODU2NDE5MzU3NTU5Mjg4NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 02a45fa03dad8526c2f51ee195e393ecaa2ff3fdd56e561c10e881db9ba36c3a |
| hovercard-subject-tag | issue:514895051 |
| 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/684/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d2845e67f86f3445c910c6b9ec92430b4c862f34838779be6c2750ff4430767a/python/typing/issues/684 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d2845e67f86f3445c910c6b9ec92430b4c862f34838779be6c2750ff4430767a/python/typing/issues/684 |
| og:image:alt | Referenced from python/mypy#7818 We use an Ellipsis as an easy-to-understand, easy-to-import sentinel value to mean "everything else". But it's not possible to use fully with type checking, since m... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | max-sixty |
| hostname | github.com |
| expected-hostname | github.com |
| None | 25854482a1773a7c1ebb8be3d2bc1c6e61d82d78126be63b5044474a86d44d9e |
| 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 | e4f5c239e31f1f680e6bbc419ff92d774da616ec |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width