Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Unify datetime import in all files #4605

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

Merged
merged 16 commits into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ The following wonderful people contributed directly or indirectly to this projec
- `Ambro17 <https://github.com/Ambro17>`_
- `Andrej Zhilenkov <https://github.com/Andrej730>`_
- `Anton Tagunov <https://github.com/anton-tagunov>`_
- `Anya Marcano <https://github.com/AnyaMarcanito>`
- `Avanatiker <https://github.com/Avanatiker>`_
- `Balduro <https://github.com/Balduro>`_
- `Bibo-Joshi <https://github.com/Bibo-Joshi>`_
Expand Down Expand Up @@ -58,12 +59,14 @@ The following wonderful people contributed directly or indirectly to this projec
- `gamgi <https://github.com/gamgi>`_
- `Gauthamram Ravichandran <https://github.com/GauthamramRavichandran>`_
- `Harshil <https://github.com/harshil21>`_
- `Henry Galue <https://github.com/henryg311>`
- `Hugo Damer <https://github.com/HakimusGIT>`_
- `ihoru <https://github.com/ihoru>`_
- `Iulian Onofrei <https://github.com/revolter>`_
- `Jainam Oswal <https://github.com/jainamoswal>`_
- `Jasmin Bom <https://github.com/jsmnbom>`_
- `JASON0916 <https://github.com/JASON0916>`_
- `Jeamhowards Montiel <https://github.com/Jeam-zx>`
- `jeffffc <https://github.com/jeffffc>`_
- `Jelle Besseling <https://github.com/pingiun>`_
- `jh0ker <https://github.com/jh0ker>`_
Expand All @@ -72,6 +75,7 @@ The following wonderful people contributed directly or indirectly to this projec
- `Joscha Götzer <https://github.com/Rostgnom>`_
- `jossalgon <https://github.com/jossalgon>`_
- `JRoot3D <https://github.com/JRoot3D>`_
- `Juan Cuevas <https://github.com/cuevasrja>`
- `kenjitagawa <https://github.com/kenjitagawa>`_
- `kennethcheo <https://github.com/kennethcheo>`_
- `Kirill Vasin <https://github.com/vasinkd>`_
Expand All @@ -87,6 +91,7 @@ The following wonderful people contributed directly or indirectly to this projec
- `Michael Dix <https://github.com/Eisberge>`_
- `Michael Elovskikh <https://github.com/wronglink>`_
- `Miguel C. R. <https://github.com/MiguelX413>`_
- `Miguel Salomon <https://github.com/Migueldsc12>`
- `miles <https://github.com/miles170>`_
- `Mischa Krüger <https://github.com/Makman2>`_
- `Mohd Yusuf <https://github.com/mohdyusuf2312>`_
Expand Down
4 changes: 2 additions & 2 deletions docs/auxil/tg_const_role.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
import datetime
import datetime as dtm
from enum import Enum

from docutils.nodes import Element
Expand Down Expand Up @@ -75,7 +75,7 @@ def process_link(
):
return str(value), target
if (
isinstance(value, datetime.datetime)
isinstance(value, dtm.datetime)
and value == telegram.constants.ZERO_DATE
and target in ("telegram.constants.ZERO_DATE",)
):
Expand Down
6 changes: 3 additions & 3 deletions telegram/_birthdate.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains an object that represents a Telegram Birthday."""
from datetime import date
import datetime as dtm
from typing import Optional

from telegram._telegramobject import TelegramObject
Expand Down Expand Up @@ -70,7 +70,7 @@ def __init__(

self._freeze()

def to_date(self, year: Optional[int] = None) -> date:
def to_date(self, year: Optional[int] = None) -> dtm.date:
"""Return the birthdate as a date object.

.. versionchanged:: 21.2
Expand All @@ -89,4 +89,4 @@ def to_date(self, year: Optional[int] = None) -> date:
"The `year` argument is required if the `year` attribute was not present."
)

return date(year or self.year, self.month, self.day) # type: ignore[arg-type]
return dtm.date(year or self.year, self.month, self.day) # type: ignore[arg-type]
18 changes: 9 additions & 9 deletions telegram/_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
import asyncio
import contextlib
import copy
import datetime as dtm
import pickle
from collections.abc import Sequence
from datetime import datetime, timedelta
from types import TracebackType
from typing import (
TYPE_CHECKING,
Expand Down Expand Up @@ -3815,7 +3815,7 @@ async def ban_chat_member(
self,
chat_id: Union[str, int],
user_id: int,
until_date: Optional[Union[int, datetime]] = None,
until_date: Optional[Union[int, dtm.datetime]] = None,
revoke_messages: Optional[bool] = None,
*,
read_timeout: ODVInput[float] = DEFAULT_NONE,
Expand Down Expand Up @@ -5451,7 +5451,7 @@ async def restrict_chat_member(
chat_id: Union[str, int],
user_id: int,
permissions: ChatPermissions,
until_date: Optional[Union[int, datetime]] = None,
until_date: Optional[Union[int, dtm.datetime]] = None,
use_independent_chat_permissions: Optional[bool] = None,
*,
read_timeout: ODVInput[float] = DEFAULT_NONE,
Expand Down Expand Up @@ -5788,7 +5788,7 @@ async def export_chat_invite_link(
async def create_chat_invite_link(
self,
chat_id: Union[str, int],
expire_date: Optional[Union[int, datetime]] = None,
expire_date: Optional[Union[int, dtm.datetime]] = None,
member_limit: Optional[int] = None,
name: Optional[str] = None,
creates_join_request: Optional[bool] = None,
Expand Down Expand Up @@ -5864,7 +5864,7 @@ async def edit_chat_invite_link(
self,
chat_id: Union[str, int],
invite_link: Union[str, "ChatInviteLink"],
expire_date: Optional[Union[int, datetime]] = None,
expire_date: Optional[Union[int, dtm.datetime]] = None,
member_limit: Optional[int] = None,
name: Optional[str] = None,
creates_join_request: Optional[bool] = None,
Expand Down Expand Up @@ -6233,7 +6233,7 @@ async def set_user_emoji_status(
self,
user_id: int,
emoji_status_custom_emoji_id: Optional[str] = None,
emoji_status_expiration_date: Optional[Union[int, datetime]] = None,
emoji_status_expiration_date: Optional[Union[int, dtm.datetime]] = None,
*,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
Expand Down Expand Up @@ -7159,7 +7159,7 @@ async def send_poll(
explanation: Optional[str] = None,
explanation_parse_mode: ODVInput[str] = DEFAULT_NONE,
open_period: Optional[int] = None,
close_date: Optional[Union[int, datetime]] = None,
close_date: Optional[Union[int, dtm.datetime]] = None,
explanation_entities: Optional[Sequence["MessageEntity"]] = None,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
Expand Down Expand Up @@ -8125,7 +8125,7 @@ async def create_invoice_link(
send_phone_number_to_provider: Optional[bool] = None,
send_email_to_provider: Optional[bool] = None,
is_flexible: Optional[bool] = None,
subscription_period: Optional[Union[int, timedelta]] = None,
subscription_period: Optional[Union[int, dtm.timedelta]] = None,
business_connection_id: Optional[str] = None,
*,
read_timeout: ODVInput[float] = DEFAULT_NONE,
Expand Down Expand Up @@ -8248,7 +8248,7 @@ async def create_invoice_link(
"send_email_to_provider": send_email_to_provider,
"subscription_period": (
subscription_period.total_seconds()
if isinstance(subscription_period, timedelta)
if isinstance(subscription_period, dtm.timedelta)
else subscription_period
),
"business_connection_id": business_connection_id,
Expand Down
7 changes: 3 additions & 4 deletions telegram/_business.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/]
"""This module contains the Telegram Business related classes."""

import datetime as dtm
from collections.abc import Sequence
from datetime import datetime
from typing import TYPE_CHECKING, Optional

from telegram._chat import Chat
Expand Down Expand Up @@ -81,7 +80,7 @@ def __init__(
id: str,
user: "User",
user_chat_id: int,
date: datetime,
date: dtm.datetime,
can_reply: bool,
is_enabled: bool,
*,
Expand All @@ -91,7 +90,7 @@ def __init__(
self.id: str = id
self.user: User = user
self.user_chat_id: int = user_chat_id
self.date: datetime = date
self.date: dtm.datetime = date
self.can_reply: bool = can_reply
self.is_enabled: bool = is_enabled

Expand Down
12 changes: 6 additions & 6 deletions telegram/_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains an object that represents a Telegram Chat."""
import datetime as dtm
from collections.abc import Sequence
from datetime import datetime
from html import escape
from typing import TYPE_CHECKING, Final, Optional, Union

Expand Down Expand Up @@ -384,7 +384,7 @@ async def ban_member(
self,
user_id: int,
revoke_messages: Optional[bool] = None,
until_date: Optional[Union[int, datetime]] = None,
until_date: Optional[Union[int, dtm.datetime]] = None,
*,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
Expand Down Expand Up @@ -656,7 +656,7 @@ async def restrict_member(
self,
user_id: int,
permissions: ChatPermissions,
until_date: Optional[Union[int, datetime]] = None,
until_date: Optional[Union[int, dtm.datetime]] = None,
use_independent_chat_permissions: Optional[bool] = None,
*,
read_timeout: ODVInput[float] = DEFAULT_NONE,
Expand Down Expand Up @@ -2116,7 +2116,7 @@ async def send_poll(
explanation: Optional[str] = None,
explanation_parse_mode: ODVInput[str] = DEFAULT_NONE,
open_period: Optional[int] = None,
close_date: Optional[Union[int, datetime]] = None,
close_date: Optional[Union[int, dtm.datetime]] = None,
explanation_entities: Optional[Sequence["MessageEntity"]] = None,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
Expand Down Expand Up @@ -2588,7 +2588,7 @@ async def export_invite_link(

async def create_invite_link(
self,
expire_date: Optional[Union[int, datetime]] = None,
expire_date: Optional[Union[int, dtm.datetime]] = None,
member_limit: Optional[int] = None,
name: Optional[str] = None,
creates_join_request: Optional[bool] = None,
Expand Down Expand Up @@ -2632,7 +2632,7 @@ async def create_invite_link(
async def edit_invite_link(
self,
invite_link: Union[str, "ChatInviteLink"],
expire_date: Optional[Union[int, datetime]] = None,
expire_date: Optional[Union[int, dtm.datetime]] = None,
member_limit: Optional[int] = None,
name: Optional[str] = None,
creates_join_request: Optional[bool] = None,
Expand Down
15 changes: 7 additions & 8 deletions telegram/_chatboost.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains the classes that represent Telegram ChatBoosts."""

import datetime as dtm
from collections.abc import Sequence
from datetime import datetime
from typing import TYPE_CHECKING, Final, Optional

from telegram import constants
Expand Down Expand Up @@ -274,17 +273,17 @@ class ChatBoost(TelegramObject):
def __init__(
self,
boost_id: str,
add_date: datetime,
expiration_date: datetime,
add_date: dtm.datetime,
expiration_date: dtm.datetime,
source: ChatBoostSource,
*,
api_kwargs: Optional[JSONDict] = None,
):
super().__init__(api_kwargs=api_kwargs)

self.boost_id: str = boost_id
self.add_date: datetime = add_date
self.expiration_date: datetime = expiration_date
self.add_date: dtm.datetime = add_date
self.expiration_date: dtm.datetime = expiration_date
self.source: ChatBoostSource = source

self._id_attrs = (self.boost_id, self.add_date, self.expiration_date, self.source)
Expand Down Expand Up @@ -386,7 +385,7 @@ def __init__(
self,
chat: Chat,
boost_id: str,
remove_date: datetime,
remove_date: dtm.datetime,
source: ChatBoostSource,
*,
api_kwargs: Optional[JSONDict] = None,
Expand All @@ -395,7 +394,7 @@ def __init__(

self.chat: Chat = chat
self.boost_id: str = boost_id
self.remove_date: datetime = remove_date
self.remove_date: dtm.datetime = remove_date
self.source: ChatBoostSource = source

self._id_attrs = (self.chat, self.boost_id, self.remove_date, self.source)
Expand Down
8 changes: 5 additions & 3 deletions telegram/_chatfullinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains an object that represents a Telegram ChatFullInfo."""
import datetime as dtm
from collections.abc import Sequence
from datetime import datetime
from typing import TYPE_CHECKING, Optional

from telegram._birthdate import Birthdate
Expand Down Expand Up @@ -422,7 +422,7 @@ def __init__(
profile_accent_color_id: Optional[int] = None,
profile_background_custom_emoji_id: Optional[str] = None,
emoji_status_custom_emoji_id: Optional[str] = None,
emoji_status_expiration_date: Optional[datetime] = None,
emoji_status_expiration_date: Optional[dtm.datetime] = None,
bio: Optional[str] = None,
has_private_forwards: Optional[bool] = None,
has_restricted_voice_and_video_messages: Optional[bool] = None,
Expand Down Expand Up @@ -486,7 +486,9 @@ def __init__(
)
self.active_usernames: tuple[str, ...] = parse_sequence_arg(active_usernames)
self.emoji_status_custom_emoji_id: Optional[str] = emoji_status_custom_emoji_id
self.emoji_status_expiration_date: Optional[datetime] = emoji_status_expiration_date
self.emoji_status_expiration_date: Optional[dtm.datetime] = (
emoji_status_expiration_date
)
self.has_aggressive_anti_spam_enabled: Optional[bool] = (
has_aggressive_anti_spam_enabled
)
Expand Down
6 changes: 3 additions & 3 deletions telegram/_chatinvitelink.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains an object that represents an invite link for a chat."""
import datetime
import datetime as dtm
from typing import TYPE_CHECKING, Optional

from telegram._telegramobject import TelegramObject
Expand Down Expand Up @@ -139,7 +139,7 @@ def __init__(
creates_join_request: bool,
is_primary: bool,
is_revoked: bool,
expire_date: Optional[datetime.datetime] = None,
expire_date: Optional[dtm.datetime] = None,
member_limit: Optional[int] = None,
name: Optional[str] = None,
pending_join_request_count: Optional[int] = None,
Expand All @@ -157,7 +157,7 @@ def __init__(
self.is_revoked: bool = is_revoked

# Optionals
self.expire_date: Optional[datetime.datetime] = expire_date
self.expire_date: Optional[dtm.datetime] = expire_date
self.member_limit: Optional[int] = member_limit
self.name: Optional[str] = name
self.pending_join_request_count: Optional[int] = (
Expand Down
6 changes: 3 additions & 3 deletions telegram/_chatjoinrequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains an object that represents a Telegram ChatJoinRequest."""
import datetime
import datetime as dtm
from typing import TYPE_CHECKING, Optional

from telegram._chat import Chat
Expand Down Expand Up @@ -106,7 +106,7 @@ def __init__(
self,
chat: Chat,
from_user: User,
date: datetime.datetime,
date: dtm.datetime,
user_chat_id: int,
bio: Optional[str] = None,
invite_link: Optional[ChatInviteLink] = None,
Expand All @@ -117,7 +117,7 @@ def __init__(
# Required
self.chat: Chat = chat
self.from_user: User = from_user
self.date: datetime.datetime = date
self.date: dtm.datetime = date
self.user_chat_id: int = user_chat_id

# Optionals
Expand Down
Loading
Loading