- Notifications
You must be signed in to change notification settings - Fork5.7k
Open
Description
What kind of feature are you missing? Where do you notice a shortcoming of PTB?
Several Telegram Objects and methods currently contain fields/parameters with names\w+_period
, wherer the integer value represents a time span in seconds.
Working with plain seconds is not very pythonic, just like working with posix timestamps isn't.
Describe the solution you'd like
In the long run, we should convert the attributes totimedelta
objects and make the parameters accept timedelta objects.
Methods Parameters
This is realtively easy, simply accepttimedelta
as well as integers and passtotalseconds()
to TG. Convertingdtm.timedelta
toint
can probably be done in the internals ofBot
or requests so that it doesn't have to happen in each bot method.
Classes
- Both attributes and arguments shouldonly accept timedeltas in the long run.
- Since this is a breaking change, we should issue a warning for now about this changing in the future and encouraging users to harden their code against the change
- For making the
timedelta
support available early, I have two ideas,both optionalWe can provide a temporary property that returns the timedelta object (e.g.xy_period_timedelta
). This would need to issue a warning stating that it will be removed oncetimedelta
is natively supported. Not overly clean …- We anyways need to make the
*_period
attributes properties to issue the deprecation warning. We could use this and look for an environment variable, sayPTB_TIMEDELTA
. If set, we return the timedelta object, otherwise theint
. → let's do this
Describe alternatives you've considered
No response
Additional context
Adding support for method parameters can be done independently of handling classes.