Title: `builtins.slice` should be generic · Issue #8647 · python/typeshed · GitHub
Open Graph Title: `builtins.slice` should be generic · Issue #8647 · python/typeshed
X Title: `builtins.slice` should be generic · Issue #8647 · python/typeshed
Description: This is a port of python/typing#159, which was closed as being out of scope, with https://github.com/srittau suggesting it maybe be more suitable for typeshed instead. It would be useful to have slice being generic and allowing type hint...
Open Graph Description: This is a port of python/typing#159, which was closed as being out of scope, with https://github.com/srittau suggesting it maybe be more suitable for typeshed instead. It would be useful to have sl...
X Description: This is a port of python/typing#159, which was closed as being out of scope, with https://github.com/srittau suggesting it maybe be more suitable for typeshed instead. It would be useful to have sl...
Opengraph URL: https://github.com/python/typeshed/issues/8647
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`builtins.slice` should be generic","articleBody":"This is a port of https://github.com/python/typing/issues/159, which was closed as being out of scope, with https://github.com/srittau suggesting it maybe be more suitable for [typeshed](https://github.com/python/typeshed) instead.\r\n\r\nIt would be useful to have `slice` being generic and allowing type hints a la\r\n\r\n- `slice[start_type, stop_type, step_type]`\r\n- `slice[S, T]` as shorthand for `slice[S, S, T]` or `slice[S, T, Any]`\r\n- `slice[T]` as shorthand for `slice[T, T, T]` or `slice[T, T, Any]` or `slice[Any, T, Any]`\r\n- `slice` as shorthand for `slice[Any, Any, Any]`\r\n\r\nSyntax wise, I would advocate for the latter options `slice[S, T]=slice[S, T, Any]`, `slice[T]=slice[Any, T, Any]` for the following reasons:\r\n\r\n1. It resembles the regular usage of `slice`: \r\n - `slice(x) = slice(None, x, None)`, \r\n - `slice(a, b) = slice(a, b, None)`\r\n2. It has better compatible with `datetime`/`timedelta` variables, which might be a common use-case.\r\n - `slice[datetime]=slice[datetime, datetime, datetime]` would be an error, because `datetimes cannot be added, only timedeltas can be added to datetimes.\r\n\r\n### Real-world examples\r\n\r\n- Datetime based slicing: Here, `start` and `stop` are `datetime`-like and `step` is `timedelta`-like (e.g. `datetime.datetime` / `datetime.timedelta`, `numpy.datetime64`/`numpy.timedelta64` or `pandas.Timestamp`/`pandas.Timedelta`)\r\n- Label based slicing via strings, for example, `pandas` allows something like `frame.loc[\"2017-07-01\":\"2017-10-31\"]` for a `DataFrame` that is indexed by a `DatetimeIndex`, this will first convert the strings to `datetime` objects and then select all rows of the table that lie between the given dates.\r\n- Similarly, one might want to select all rows of a table that lie between two float values.","author":{"url":"https://github.com/randolf-scholz","@type":"Person","name":"randolf-scholz"},"datePublished":"2022-08-29T18:34:47Z","url":"https://github.com/python/typeshed/issues/8647"}
| 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:6d42a7d7-e98a-47cc-35b8-ec3e9ac84220 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9ED4:14B836:999B6F:CCFBEF:6B00438E |
| html-safe-nonce | 4682fef690c85fdaa411fcbbf4da761b4cd8e941a4143fd3ae00324edb0767a1 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RUQ0OjE0QjgzNjo5OTlCNkY6Q0NGQkVGOjZCMDA0MzhFIiwidmlzaXRvcl9pZCI6IjQxNDg1Nzc1ODk1Mjg2NDI0NDYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 155a531855c7fa8e6c1b6ee84c9c516d7e57bca371e83064ea8151b8b42c2845 |
| hovercard-subject-tag | issue:1354719118 |
| 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/typeshed/8647/issue_layout |
| twitter:image | https://opengraph.githubassets.com/47f052d2c9a57fd4964ee0bb0830df68d269549f6c735c281ba546c63756cc0f/python/typeshed/issues/8647 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/47f052d2c9a57fd4964ee0bb0830df68d269549f6c735c281ba546c63756cc0f/python/typeshed/issues/8647 |
| og:image:alt | This is a port of python/typing#159, which was closed as being out of scope, with https://github.com/srittau suggesting it maybe be more suitable for typeshed instead. It would be useful to have sl... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | randolf-scholz |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7d0829bbde9e48b2486cb5dd6d147896eb01d32134627091f818958a935ef3f0 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/typeshed git https://github.com/python/typeshed.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 31696383 |
| octolytics-dimension-repository_nwo | python/typeshed |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 31696383 |
| octolytics-dimension-repository_network_root_nwo | python/typeshed |
| 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 | f3f3a43ca095cdea3abbb394112e971f9fdb94fa |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width