Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
c7ea5fd
Remove Python 3.7 from testing, docs and packaging
Bibo-Joshi Jun 2, 2023
f1784b5
Re-add note on CI bots
Bibo-Joshi Jun 3, 2023
03d3c33
temporarily run tests on this branch
harshil21 Jun 3, 2023
4de4643
Add missing new line
Bibo-Joshi Jun 4, 2023
457e4ef
Adopt Py3.8+ features: `missing_ok` Parameter (#3742)
Trifase Jun 4, 2023
a1c2fe7
Introduce Walrus Operator (#3749)
thefunkycat Jun 8, 2023
f663f37
Add python 3.12 to test matrix
harshil21 Jun 9, 2023
b49d03f
correct typo
harshil21 Jun 9, 2023
9d3345c
Remove Python 3.7 Workaround for `PicklePersistence` (#3740)
harshil21 Jun 9, 2023
1a3e4f7
Fix tests on py 3.12
harshil21 Jun 9, 2023
8c86a34
Merge branch 'master' into drop-py-37
Bibo-Joshi Jun 12, 2023
cf71a38
Drop `CancelledError` (#3754)
clot27 Jun 17, 2023
9181369
Make use of `@final`, `Final` and `Literal` (#3753)
Bibo-Joshi Jun 17, 2023
27a8683
fix error with `Literal`, causing tests/docs to fail (#3764)
lemontree210 Jun 19, 2023
b44e4af
Review: don't drop support for async gens for py < 3.12
harshil21 Jun 20, 2023
40c2cf3
Merge branch 'drop-py-37' into add-py-312
harshil21 Jun 20, 2023
8234f3c
Bump mypy and address review
harshil21 Jun 20, 2023
162004f
Review: Add deprecation warning & modify type hints
harshil21 Jul 2, 2023
8b73410
use 3.12 beta 3
harshil21 Jul 2, 2023
4962c48
merge master and fix conflicts
harshil21 Jul 2, 2023
9d0c980
try to fix type completeness CI check
harshil21 Jul 2, 2023
e753dd7
fix a leftover merge conflict
harshil21 Jul 2, 2023
0755fe1
bump mypy again
harshil21 Jul 2, 2023
316e500
try bumping pyright
harshil21 Jul 2, 2023
69ef58b
review: fix pyright by applying 'RT' generic
harshil21 Jul 4, 2023
816f020
Merge branch 'master' into add-py-312
Bibo-Joshi Jul 4, 2023
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
Fix tests on py 3.12
Also remove support for generators in app.create_task
  • Loading branch information
harshil21 committed Jun 9, 2023
commit 1a3e4f74d68400ea429abefeac680b49ee891b10
17 changes: 7 additions & 10 deletions telegram/ext/_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
Coroutine,
DefaultDict,
Dict,
Generator,
Generic,
List,
Mapping,
Expand Down Expand Up @@ -938,7 +937,7 @@ def __run(

def create_task(
self,
coroutine: Union[Generator[Optional["asyncio.Future[object]"], None, RT], Awaitable[RT]],
coroutine: Union[Optional["asyncio.Future[object]"], Awaitable[RT]],
update: Optional[object] = None,
) -> "asyncio.Task[RT]":
"""Thin wrapper around :func:`asyncio.create_task` that handles exceptions raised by
Expand All @@ -957,6 +956,8 @@ def create_task(

.. versionchanged:: 20.2
Accepts :class:`asyncio.Future` and generator-based coroutine functions.
.. versionchanged:: NEXT.VERSION
Since Python 3.12, generator-based coroutine functions are no longer accepted.
update (:obj:`object`, optional): If set, will be passed to :meth:`process_error`
as additional information for the error handlers. Moreover, the corresponding
:attr:`chat_data` and :attr:`user_data` entries will be updated in the next run of
Expand All @@ -969,7 +970,7 @@ def create_task(

def __create_task(
self,
coroutine: Union[Generator[Optional["asyncio.Future[object]"], None, RT], Awaitable[RT]],
coroutine: Union[Optional["asyncio.Future[object]"], Awaitable[RT]],
update: Optional[object] = None,
is_error_handler: bool = False,
) -> "asyncio.Task[RT]":
Expand Down Expand Up @@ -1004,14 +1005,12 @@ def __create_task_done_callback(self, task: asyncio.Task) -> None:

async def __create_task_callback(
self,
coroutine: Union[Generator[Optional["asyncio.Future[object]"], None, RT], Awaitable[RT]],
coroutine: Union[Optional["asyncio.Future[object]"], Awaitable[RT]],
update: Optional[object] = None,
is_error_handler: bool = False,
) -> RT:
try:
if isinstance(coroutine, Generator):
return await asyncio.create_task(coroutine)
return await coroutine
return await coroutine # type: ignore[misc]
Comment thread
Bibo-Joshi marked this conversation as resolved.
Outdated
except asyncio.CancelledError as cancel:
# TODO: in py3.8+, CancelledError is a subclass of BaseException, so we can drop this
# clause when we drop py3.7
Expand Down Expand Up @@ -1619,9 +1618,7 @@ async def process_error(
update: Optional[object],
error: Exception,
job: Optional["Job[CCT]"] = None,
coroutine: Optional[
Union[Generator[Optional["asyncio.Future[object]"], None, RT], Awaitable[RT]]
] = None,
coroutine: Optional[Union[Optional["asyncio.Future[object]"], Awaitable[RT]]] = None,
) -> bool:
"""Processes an error by passing it to all error handlers registered with
:meth:`add_error_handler`. If one of the error handlers raises
Expand Down
10 changes: 0 additions & 10 deletions tests/ext/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -1299,16 +1299,6 @@ async def callback():
out = await app.create_task(asyncio.gather(callback()))
assert out == [42]

async def test_create_task_awaiting_generator(self, app):
event = asyncio.Event()

def gen():
yield
event.set()

await app.create_task(gen())
assert event.is_set()

async def test_no_concurrent_updates(self, app):
queue = asyncio.Queue()
event_1 = asyncio.Event()
Expand Down
13 changes: 6 additions & 7 deletions tests/ext/test_basepersistence.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import enum
import functools
import logging
import sys
import time
from pathlib import Path
from typing import NamedTuple, Optional
Expand Down Expand Up @@ -377,15 +378,13 @@ def test_init_store_data_update_interval(self, bot_data, chat_data, user_data, c
assert persistence.store_data.callback_data == callback_data

def test_abstract_methods(self):
methods = list(BasePersistence.__abstractmethods__)
methods.sort()
with pytest.raises(
TypeError,
match=(
"drop_chat_data, drop_user_data, flush, get_bot_data, get_callback_data, "
"get_chat_data, get_conversations, "
"get_user_data, refresh_bot_data, refresh_chat_data, "
"refresh_user_data, update_bot_data, update_callback_data, "
"update_chat_data, update_conversation, update_user_data"
),
match=", ".join(methods)
if sys.version_info < (3, 12)
else ", ".join(f"'{i}'" for i in methods),
):
BasePersistence()

Expand Down
4 changes: 3 additions & 1 deletion tests/ext/test_picklepersistence.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import gzip
import os
import pickle
import sys
from pathlib import Path

import pytest
Expand Down Expand Up @@ -872,7 +873,8 @@ async def test_custom_pickler_unpickler_simple(
"function was specified."
)
with Path("pickletest_chat_data").open("rb") as f, pytest.raises(
pickle.UnpicklingError, match=err_msg
pickle.UnpicklingError,
match=err_msg if sys.version_info < (3, 12) else err_msg.replace("\n", " "),
):
pickle.load(f)

Expand Down