Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
f5bdffd
Add `typing_extensions`
aelkheir Aug 19, 2026
d6c35bd
Set ruff `typing-extensions=false`
aelkheir Aug 19, 2026
ae4210c
Add `tg{dataclass,field}` helpers
aelkheir Aug 21, 2026
e20a074
Do ground work in `TelegramObject`
aelkheir Aug 19, 2026
b4bbfa3
Add runtime support for specifier parameter `alias`
aelkheir Aug 22, 2026
0026d93
Some typing improvements to `_utils/dataclass.py`
aelkheir Aug 23, 2026
12abacf
Migrate classes direclty under `telegram/`
aelkheir Aug 23, 2026
d19ccdc
Add chango fragment for PR #5334
aelkheir Aug 23, 2026
ea65eea
Finish up classes under `telegram/**/`
aelkheir Sep 10, 2026
8218317
Migrate `Bot` and `ExtBot`
aelkheir Sep 13, 2026
60c1ea0
Remove `test_slot_behaviour()` where its automated
aelkheir Sep 12, 2026
cf8bea0
Add missing default `None` to optional fields
aelkheir Sep 13, 2026
edb225e
Fix some enum copy-paste typos
aelkheir Sep 13, 2026
9e6d558
Override dataclasses generated `__hash__()`
aelkheir Sep 15, 2026
2d88fd0
Handle annotation replacements in generated` __init__`
aelkheir Sep 15, 2026
b17b6b8
Remove `__[get/set]state__` that dataclasses generate
aelkheir Sep 17, 2026
bfc7812
Update two tests that relied on uneeded type coercion
aelkheir Sep 15, 2026
9c53a39
Fix a `test_chatmemberupdated` failure
aelkheir Sep 15, 2026
0a33d49
Update `test_telegramobject` to use `@tg_dataclass()`
aelkheir Sep 15, 2026
37705e0
Remove old "deepcopy preserves freezing" test
aelkheir Sep 17, 2026
92dd955
Deprecate test_telegramobject `test_subclasses_have_api_kwargs`
aelkheir Sep 17, 2026
057fde2
Define `_CredentialsBase.*_hash` aliases as fields
aelkheir Sep 15, 2026
fbd5b8b
Handle all the `[un]freezing` in test suite
aelkheir Sep 17, 2026
cf6485b
Migrate `_inputmedia` classes
aelkheir Sep 20, 2026
908a07b
Simplify `passportelementerrors` migration
aelkheir Sep 20, 2026
bf850c9
Restore TO hashing behaviour and add tests for it
aelkheir Sep 21, 2026
557c9b9
Restore equality for direct TO instances
aelkheir Sep 21, 2026
2aa3421
Fix minor bugs in some field definitions
aelkheir Sep 21, 2026
01bb8c5
Document all breaking changes in changelog
aelkheir Sep 22, 2026
bd568f7
Merge remote-tracking branch 'upstream/master' into dataclasses
aelkheir Sep 22, 2026
2389cae
Fix some `test_poll` failures
aelkheir Sep 22, 2026
ed5bc39
Unify TelegramObject comparison tests after removing warnings
aelkheir Sep 22, 2026
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
Prev Previous commit
Next Next commit
Finish up classes under telegram/**/
Except `inputmedia.py` classes and `Bot`
  • Loading branch information
aelkheir committed Sep 10, 2026
commit ea65eeaad906f7ac2876cfe940f737938794fb9e
1 change: 0 additions & 1 deletion docs/auxil/sphinx_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
PRIVATE_BASE_CLASSES = {
"_ChatUserBaseFilter": "MessageFilter",
"_Dice": "MessageFilter",
"_BaseThumbedMedium": "TelegramObject",
"_BaseMedium": "TelegramObject",
"_CredentialsBase": "TelegramObject",
"_ChatBase": "TelegramObject",
Expand Down
2 changes: 1 addition & 1 deletion docs/source/telegram.animation.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Animation
=========

.. Also lists methods of _BaseThumbedMedium, but not the ones of TelegramObject
.. Also lists methods of _BaseMedium, but not the ones of TelegramObject

.. autoclass:: telegram.Animation
:members:
Expand Down
2 changes: 1 addition & 1 deletion docs/source/telegram.audio.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Audio
=====

.. Also lists methods of _BaseThumbedMedium, but not the ones of TelegramObject
.. Also lists methods of _BaseMedium, but not the ones of TelegramObject

.. autoclass:: telegram.Audio
:members:
Expand Down
2 changes: 1 addition & 1 deletion docs/source/telegram.document.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Document
========
.. Also lists methods of _BaseThumbedMedium, but not the ones of TelegramObject
.. Also lists methods of _BaseMedium, but not the ones of TelegramObject

.. autoclass:: telegram.Document
:members:
Expand Down
2 changes: 1 addition & 1 deletion docs/source/telegram.sticker.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Sticker
=======

.. Also lists methods of _BaseThumbedMedium, but not the ones of TelegramObject
.. Also lists methods of _BaseMedium, but not the ones of TelegramObject

.. autoclass:: telegram.Sticker
:members:
Expand Down
2 changes: 1 addition & 1 deletion docs/source/telegram.video.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Video
=====

.. Also lists methods of _BaseThumbedMedium, but not the ones of TelegramObject
.. Also lists methods of _BaseMedium, but not the ones of TelegramObject

.. autoclass:: telegram.Video
:members:
Expand Down
2 changes: 1 addition & 1 deletion docs/source/telegram.videonote.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
VideoNote
=========

.. Also lists methods of _BaseThumbedMedium, but not the ones of TelegramObject
.. Also lists methods of _BaseMedium, but not the ones of TelegramObject

.. autoclass:: telegram.VideoNote
:members:
Expand Down
2 changes: 1 addition & 1 deletion docs/source/telegram.voice.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Voice
=====

.. Also lists methods of _BaseThumbedMedium, but not the ones of TelegramObject
.. Also lists methods of _BaseMedium, but not the ones of TelegramObject

.. autoclass:: telegram.Voice
:members:
Expand Down
26 changes: 5 additions & 21 deletions src/telegram/_files/_basemedium.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@
from typing import TYPE_CHECKING

from telegram._telegramobject import TelegramObject
from telegram._utils.dataclass import tg_dataclass, tg_field
from telegram._utils.defaultvalue import DEFAULT_NONE
from telegram._utils.types import JSONDict, ODVInput

if TYPE_CHECKING:
from telegram import File


@tg_dataclass()
class _BaseMedium(TelegramObject):
"""Base class for objects representing the various media file types.
Objects of this class are comparable in terms of equality. Two objects of this class are
Expand All @@ -39,36 +41,18 @@ class _BaseMedium(TelegramObject):
file_unique_id (:obj:`str`): Unique identifier for this file, which
is supposed to be the same over time and for different bots.
Can't be used to download or reuse the file.
file_size (:obj:`int`, optional): File size.

Attributes:
file_id (:obj:`str`): File identifier.
file_unique_id (:obj:`str`): Unique identifier for this file, which
is supposed to be the same over time and for different bots.
Can't be used to download or reuse the file.
file_size (:obj:`int`): Optional. File size.

"""

__slots__ = ("file_id", "file_size", "file_unique_id")

def __init__(
self,
file_id: str,
file_unique_id: str,
file_size: int | None = None,
*,
api_kwargs: JSONDict | None = None,
):
super().__init__(api_kwargs=api_kwargs)

# Required
self.file_id: str = str(file_id)
self.file_unique_id: str = str(file_unique_id)
# Optionals
self.file_size: int | None = file_size

self._id_attrs = (self.file_unique_id,)
# Required
file_id: str = tg_field()
file_unique_id: str = tg_field(compare=True)

async def get_file(
self,
Expand Down
84 changes: 0 additions & 84 deletions src/telegram/_files/_basethumbedmedium.py

This file was deleted.

47 changes: 13 additions & 34 deletions src/telegram/_files/animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@

import datetime as dtm

from telegram._files._basethumbedmedium import _BaseThumbedMedium
from telegram._files._basemedium import _BaseMedium
from telegram._files.photosize import PhotoSize
from telegram._utils.argumentparsing import to_timedelta
from telegram._utils.dataclass import tg_dataclass, tg_field
from telegram._utils.datetime import get_timedelta_value
from telegram._utils.types import JSONDict, TimePeriod


class Animation(_BaseThumbedMedium):
@tg_dataclass()
class Animation(_BaseMedium):
"""This object represents an animation file (GIF or H.264/MPEG-4 AVC video without sound).

Objects of this class are comparable in terms of equality. Two objects of this class are
Expand Down Expand Up @@ -80,37 +81,15 @@ class Animation(_BaseThumbedMedium):

"""

__slots__ = ("_duration", "file_name", "height", "mime_type", "width")

def __init__(
self,
file_id: str,
file_unique_id: str,
width: int,
height: int,
duration: TimePeriod,
file_name: str | None = None,
mime_type: str | None = None,
file_size: int | None = None,
thumbnail: PhotoSize | None = None,
*,
api_kwargs: JSONDict | None = None,
):
super().__init__(
file_id=file_id,
file_unique_id=file_unique_id,
file_size=file_size,
api_kwargs=api_kwargs,
thumbnail=thumbnail,
)
with self._unfrozen():
# Required
self.width: int = width
self.height: int = height
self._duration: dtm.timedelta = to_timedelta(duration)
# Optional
self.mime_type: str | None = mime_type
self.file_name: str | None = file_name
# Required
width: int = tg_field()
height: int = tg_field()
_duration: dtm.timedelta = tg_field(alias="duration", converter=to_timedelta)
# Optional
file_name: str | None = tg_field(default=None)
mime_type: str | None = tg_field(default=None)
file_size: int | None = tg_field(default=None)
thumbnail: PhotoSize | None = tg_field(default=None)

@property
def duration(self) -> int | dtm.timedelta:
Expand Down
47 changes: 13 additions & 34 deletions src/telegram/_files/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@

import datetime as dtm

from telegram._files._basethumbedmedium import _BaseThumbedMedium
from telegram._files._basemedium import _BaseMedium
from telegram._files.photosize import PhotoSize
from telegram._utils.argumentparsing import to_timedelta
from telegram._utils.dataclass import tg_dataclass, tg_field
from telegram._utils.datetime import get_timedelta_value
from telegram._utils.types import JSONDict, TimePeriod


class Audio(_BaseThumbedMedium):
@tg_dataclass()
class Audio(_BaseMedium):
"""This object represents an audio file to be treated as music by the Telegram clients.

Objects of this class are comparable in terms of equality. Two objects of this class are
Expand Down Expand Up @@ -82,37 +83,15 @@ class Audio(_BaseThumbedMedium):

"""

__slots__ = ("_duration", "file_name", "mime_type", "performer", "title")

def __init__(
self,
file_id: str,
file_unique_id: str,
duration: TimePeriod,
performer: str | None = None,
title: str | None = None,
mime_type: str | None = None,
file_size: int | None = None,
file_name: str | None = None,
thumbnail: PhotoSize | None = None,
*,
api_kwargs: JSONDict | None = None,
):
super().__init__(
file_id=file_id,
file_unique_id=file_unique_id,
file_size=file_size,
thumbnail=thumbnail,
api_kwargs=api_kwargs,
)
with self._unfrozen():
# Required
self._duration: dtm.timedelta = to_timedelta(duration)
# Optional
self.performer: str | None = performer
self.title: str | None = title
self.mime_type: str | None = mime_type
self.file_name: str | None = file_name
# Required
_duration: dtm.timedelta = tg_field(alias="duration", converter=to_timedelta)
# Optional
performer: str | None = tg_field(default=None)
title: str | None = tg_field(default=None)
mime_type: str | None = tg_field(default=None)
file_size: int | None = tg_field(default=None)
file_name: str | None = tg_field(default=None)
thumbnail: PhotoSize | None = tg_field(default=None)

@property
def duration(self) -> int | dtm.timedelta:
Expand Down
Loading
Loading