From a28201a5e60d846c68b41c9aa19ab21bd40ad83f Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Tue, 14 Jul 2026 12:39:33 -0700 Subject: [PATCH] test(telegram): gate slots premise assert on runtimes without instance __dict__ The read-only premise only holds on Python 3.13+ where the full PTB request MRO is slotted. CI runs 3.11/3.12 where BaseRequest instances still carry a __dict__, so the unconditional pytest.raises failed. The behavioral half of the test (subclass re-tag instruments and records) runs everywhere. --- tests/test_telegram_polling_progress_ptb.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/test_telegram_polling_progress_ptb.py b/tests/test_telegram_polling_progress_ptb.py index 1eab796354cd..d91419d506c1 100644 --- a/tests/test_telegram_polling_progress_ptb.py +++ b/tests/test_telegram_polling_progress_ptb.py @@ -270,10 +270,14 @@ async def test_slotted_request_instrumented_without_read_only_error(): adapter._polling_conflict_count = 3 request = _SlottedEnvelopeRequest(b'{"ok":true,"result":[]}') - # Guard the premise: the slotted instance rejects the old monkey-patch, - # exactly as PTB's HTTPXRequest does on Python 3.13. - with pytest.raises(AttributeError, match="read-only"): - request.do_request = lambda *a, **k: None + # Guard the premise where the runtime actually enforces it: PTB's request + # MRO is only fully slotted on Python 3.13+ (contextlib's + # AbstractAsyncContextManager gained ``__slots__ = ()`` there). On older + # runtimes the instance still carries a ``__dict__`` and the legacy + # monkey-patch is accepted, so the read-only premise cannot be asserted. + if not hasattr(request, "__dict__"): + with pytest.raises(AttributeError, match="read-only"): + request.do_request = lambda *a, **k: None instrumented = adapter._instrument_polling_request(request) context_token = tg_adapter._POLLING_GENERATION_CONTEXT.set(generation)