Skip to content

Commit 3a1b48d

Browse files
Add Python 3.14 support
Co-authored-by: KurimuzonAkuma <[email protected]>
1 parent 84ebb7e commit 3a1b48d

File tree

5 files changed

+50
-6
lines changed

5 files changed

+50
-6
lines changed

.github/workflows/python.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
strategy:
1414
matrix:
1515
os: [ubuntu-22.04, macos-14]
16-
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
16+
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
1717

1818
steps:
1919
- uses: actions/checkout@v4

compiler/api/template/type.txt

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,26 @@
22

33
{warning}
44

5-
from typing import Union
5+
from typing import TYPE_CHECKING, Union
66
from pyrogram import raw
7+
from pyrogram.raw.core import BaseTypeMeta
78

8-
{name} = Union[{types}]
9-
{name}.__doc__ = """
10-
{docstring}
11-
"""
9+
10+
if TYPE_CHECKING:
11+
{name} = Union[{types}]
12+
else:
13+
# noinspection PyRedeclaration
14+
class {name}(metaclass=BaseTypeMeta): # type: ignore
15+
"""{docstring}
16+
"""
17+
18+
QUALNAME = "pyrogram.raw.base.{qualname}"
19+
__union_types__ = Union[{types}]
20+
21+
def __init__(self):
22+
raise TypeError(
23+
"Base types can only be used for type checking purposes: "
24+
"you tried to use a base type instance as argument, "
25+
"but you need to instantiate one of its constructors instead. "
26+
"More info: https://telegramplayground.github.io/pyrogram/telegram/base/{doc_name}"
27+
)

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ classifiers = [
2020
"Programming Language :: Python :: 3.11",
2121
"Programming Language :: Python :: 3.12",
2222
"Programming Language :: Python :: 3.13",
23+
"Programming Language :: Python :: 3.14",
2324
"Programming Language :: Python :: Implementation",
2425
"Programming Language :: Python :: Implementation :: CPython",
2526
"Programming Language :: Python :: Implementation :: PyPy",

pyrogram/raw/core/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@
2828
from .primitives.int import Int, Long, Int128, Int256
2929
from .primitives.string import String
3030
from .primitives.vector import Vector
31+
from .base_type_meta import BaseTypeMeta
3132
from .tl_object import TLObject
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Pyrogram - Telegram MTProto API Client Library for Python
2+
# Copyright (C) 2017-present <https://github.com/KurimuzonAkuma>
3+
#
4+
# This file is part of Kurigram.
5+
#
6+
# Pyrogram is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU Lesser General Public License as published
8+
# by the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
10+
#
11+
# Pyrogram is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU Lesser General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU Lesser General Public License
17+
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
18+
19+
from typing import get_args
20+
21+
class BaseTypeMeta(type):
22+
def __instancecheck__(cls, instance):
23+
return isinstance(instance, get_args(cls.__union_types__))
24+
25+
def __subclasscheck__(cls, subclass):
26+
return issubclass(subclass, get_args(cls.__union_types__))

0 commit comments

Comments
 (0)