MCPcopy Create free account
hub / github.com/crewAIInc/crewAI / _patch_vcrpy_aiohttp_compat

Function _patch_vcrpy_aiohttp_compat

conftest.py:16–101  ·  view source on GitHub ↗

Keep vcrpy's aiohttp stub working under aiohttp 3.14.0. aiohttp 3.14.0 (pulled in to fix GHSA-jg22-mg44-37j8 and GHSA-hg6j-4rv6-33pg): * removed ``aiohttp.streams.AsyncStreamReaderMixin`` (folded into ``StreamReader``), which vcrpy's ``MockStream`` still subclasses -- vcr's patch

()

Source from the content-addressed store, hash-verified

14
15
16def _patch_vcrpy_aiohttp_compat() -> None:
17 """Keep vcrpy's aiohttp stub working under aiohttp 3.14.0.
18
19 aiohttp 3.14.0 (pulled in to fix GHSA-jg22-mg44-37j8 and GHSA-hg6j-4rv6-33pg):
20 * removed ``aiohttp.streams.AsyncStreamReaderMixin`` (folded into ``StreamReader``),
21 which vcrpy's ``MockStream`` still subclasses -- vcr's patch machinery then raises
22 ``AttributeError`` at collection time; and
23 * added a required ``stream_writer`` keyword-only arg to ``ClientResponse.__init__``,
24 which vcrpy's ``MockClientResponse`` does not pass -- raising ``TypeError`` at
25 cassette playback.
26
27 Restore the mixin, then rebuild ``MockClientResponse``'s ``super().__init__`` call from
28 the live ``ClientResponse`` signature (defaulting every required keyword-only arg to
29 ``None``, mirroring vcrpy's original call) so it also survives future aiohttp additions.
30 """
31 import asyncio
32 import inspect
33
34 from aiohttp import streams
35 from aiohttp.client_reqrep import ClientResponse
36
37 if not hasattr(streams, "AsyncStreamReaderMixin"):
38
39 class AsyncStreamReaderMixin:
40 __slots__ = ()
41
42 def __aiter__(self) -> streams.AsyncStreamIterator[bytes]:
43 return streams.AsyncStreamIterator(self.readline) # type: ignore[attr-defined]
44
45 def iter_chunked(self, n: int) -> streams.AsyncStreamIterator[bytes]:
46 return streams.AsyncStreamIterator(lambda: self.read(n)) # type: ignore[attr-defined]
47
48 def iter_any(self) -> streams.AsyncStreamIterator[bytes]:
49 return streams.AsyncStreamIterator(self.readany) # type: ignore[attr-defined]
50
51 def iter_chunks(self) -> streams.ChunkTupleAsyncStreamIterator:
52 return streams.ChunkTupleAsyncStreamIterator(self) # type: ignore[arg-type]
53
54 streams.AsyncStreamReaderMixin = AsyncStreamReaderMixin # type: ignore[attr-defined]
55
56 # Importing the stub builds MockStream/MockClientResponse, so it must run after the
57 # mixin is restored above.
58 import vcr.stubs.aiohttp_stubs as aiohttp_stubs # type: ignore[import-untyped]
59
60 if getattr(aiohttp_stubs.MockClientResponse, "_crewai_aiohttp_patched", False):
61 return
62
63 keyword_only = [
64 name
65 for name, param in inspect.signature(ClientResponse.__init__).parameters.items()
66 if param.kind is inspect.Parameter.KEYWORD_ONLY
67 ]
68
69 class _NullStreamWriter:
70 # aiohttp 3.14.0 reads stream_writer.output_size in the "request already
71 # sent" branch (writer is None), so None is not enough -- supply a stub.
72 output_size = 0
73

Callers 1

conftest.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected