Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Usedatetime.timedelta to Represent Time Periods #4575

Labels
Milestone
@Bibo-Joshi

Description

@Bibo-Joshi

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 thetimedelta support available early, I have two ideas,both optional
    • We 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp