-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
builtins.slice
should be generic
#8647
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
An example of heterogeneous types (although a little cute) is to do |
Related https://peps.python.org/pep-0696/#using-another-typevarlike-as-the-default which were my thoughts on the matter |
Marking as deferred until and unless PEP-696 is accepted by the Steering Council and implemented by all major type checkers |
Little status update:
|
Cf. #11422 for the feature tracker. |
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 hints a laslice[start_type, stop_type, step_type]
slice[S, T]
as shorthand forslice[S, S, T]
orslice[S, T, Any]
slice[T]
as shorthand forslice[T, T, T]
orslice[T, T, Any]
orslice[Any, T, Any]
slice
as shorthand forslice[Any, Any, Any]
Syntax 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:slice
:slice(x) = slice(None, x, None)
,slice(a, b) = slice(a, b, None)
datetime
/timedelta
variables, which might be a common use-case.slice[datetime]=slice[datetime, datetime, datetime]
would be an error, because `datetimes cannot be added, only timedeltas can be added to datetimes.Real-world examples
start
andstop
aredatetime
-like andstep
istimedelta
-like (e.g.datetime.datetime
/datetime.timedelta
,numpy.datetime64
/numpy.timedelta64
orpandas.Timestamp
/pandas.Timedelta
)pandas
allows something likeframe.loc["2017-07-01":"2017-10-31"]
for aDataFrame
that is indexed by aDatetimeIndex
, this will first convert the strings todatetime
objects and then select all rows of the table that lie between the given dates.The text was updated successfully, but these errors were encountered: