vercel-internal-core-bundle 0.1.2__tar.gz → 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. {vercel_internal_core_bundle-0.1.2 → vercel_internal_core_bundle-0.2.0}/PKG-INFO +14 -3
  2. {vercel_internal_core_bundle-0.1.2 → vercel_internal_core_bundle-0.2.0}/README.md +11 -0
  3. {vercel_internal_core_bundle-0.1.2 → vercel_internal_core_bundle-0.2.0}/pyproject.toml +2 -2
  4. {vercel_internal_core_bundle-0.1.2 → vercel_internal_core_bundle-0.2.0}/vercel/_internal/core/byte_stream.py +1 -5
  5. {vercel_internal_core_bundle-0.1.2 → vercel_internal_core_bundle-0.2.0}/vercel/_internal/core/http/__init__.py +4 -0
  6. vercel_internal_core_bundle-0.2.0/vercel/_internal/core/http/_compat.py +61 -0
  7. {vercel_internal_core_bundle-0.1.2 → vercel_internal_core_bundle-0.2.0}/vercel/_internal/core/http/httpx.py +1 -1
  8. {vercel_internal_core_bundle-0.1.2 → vercel_internal_core_bundle-0.2.0}/vercel/_internal/core/http/retry.py +1 -1
  9. {vercel_internal_core_bundle-0.1.2 → vercel_internal_core_bundle-0.2.0}/vercel/_internal/core/http/transport.py +73 -46
  10. {vercel_internal_core_bundle-0.1.2 → vercel_internal_core_bundle-0.2.0}/vercel/_internal/core/polyfills/__init__.py +2 -2
  11. vercel_internal_core_bundle-0.2.0/vercel/_internal/core/polyfills/_typing.py +13 -0
  12. {vercel_internal_core_bundle-0.1.2 → vercel_internal_core_bundle-0.2.0}/vercel/_internal/core/session.py +19 -13
  13. vercel_internal_core_bundle-0.2.0/vercel/_internal/core/version.py +1 -0
  14. vercel_internal_core_bundle-0.1.2/vercel/_internal/core/polyfills/_typing.py +0 -8
  15. vercel_internal_core_bundle-0.1.2/vercel/_internal/core/version.py +0 -1
  16. {vercel_internal_core_bundle-0.1.2 → vercel_internal_core_bundle-0.2.0}/LICENSE +0 -0
  17. {vercel_internal_core_bundle-0.1.2 → vercel_internal_core_bundle-0.2.0}/_vercel_hatch_build.py +0 -0
  18. {vercel_internal_core_bundle-0.1.2 → vercel_internal_core_bundle-0.2.0}/hatch_build.py +0 -0
  19. {vercel_internal_core_bundle-0.1.2 → vercel_internal_core_bundle-0.2.0}/vercel/_internal/core/__init__.py +0 -0
  20. {vercel_internal_core_bundle-0.1.2 → vercel_internal_core_bundle-0.2.0}/vercel/_internal/core/_vendor/__init__.py +0 -0
  21. {vercel_internal_core_bundle-0.1.2 → vercel_internal_core_bundle-0.2.0}/vercel/_internal/core/_vendor/vendor.txt +0 -0
  22. {vercel_internal_core_bundle-0.1.2 → vercel_internal_core_bundle-0.2.0}/vercel/_internal/core/errors.py +0 -0
  23. {vercel_internal_core_bundle-0.1.2 → vercel_internal_core_bundle-0.2.0}/vercel/_internal/core/http/config.py +0 -0
  24. {vercel_internal_core_bundle-0.1.2 → vercel_internal_core_bundle-0.2.0}/vercel/_internal/core/iter_coroutine.py +0 -0
  25. {vercel_internal_core_bundle-0.1.2 → vercel_internal_core_bundle-0.2.0}/vercel/_internal/core/options.py +0 -0
  26. {vercel_internal_core_bundle-0.1.2 → vercel_internal_core_bundle-0.2.0}/vercel/_internal/core/polyfills/_datetime.py +0 -0
  27. {vercel_internal_core_bundle-0.1.2 → vercel_internal_core_bundle-0.2.0}/vercel/_internal/core/polyfills/_strenum.py +0 -0
  28. {vercel_internal_core_bundle-0.1.2 → vercel_internal_core_bundle-0.2.0}/vercel/_internal/core/polyfills/_strenum_impl.py +0 -0
  29. {vercel_internal_core_bundle-0.1.2 → vercel_internal_core_bundle-0.2.0}/vercel/_internal/core/py.typed +0 -0
  30. {vercel_internal_core_bundle-0.1.2 → vercel_internal_core_bundle-0.2.0}/vercel/_internal/core/time.py +0 -0
  31. {vercel_internal_core_bundle-0.1.2 → vercel_internal_core_bundle-0.2.0}/vercel/_internal/core/typeutils.py +0 -0
  32. {vercel_internal_core_bundle-0.1.2 → vercel_internal_core_bundle-0.2.0}/vercel/_internal/core/url.py +0 -0
  33. {vercel_internal_core_bundle-0.1.2 → vercel_internal_core_bundle-0.2.0}/vercel/api/__init__.py +0 -0
  34. {vercel_internal_core_bundle-0.1.2 → vercel_internal_core_bundle-0.2.0}/vercel/api/py.typed +0 -0
  35. {vercel_internal_core_bundle-0.1.2 → vercel_internal_core_bundle-0.2.0}/vercel/errors/__init__.py +0 -0
  36. {vercel_internal_core_bundle-0.1.2 → vercel_internal_core_bundle-0.2.0}/vercel/errors/py.typed +0 -0
@@ -1,11 +1,11 @@
1
- Metadata-Version: 2.4
1
+ Metadata-Version: 2.5
2
2
  Name: vercel-internal-core-bundle
3
- Version: 0.1.2
3
+ Version: 0.2.0
4
4
  Summary: Shared internal runtime for Vercel Python packages
5
5
  License-Expression: MIT
6
6
  License-File: LICENSE
7
7
  Requires-Python: >=3.10
8
- Requires-Dist: vercel-internal-shared-vendored-deps>=0.1.1
8
+ Requires-Dist: vercel-internal-shared-vendored-deps>=0.1.2
9
9
  Description-Content-Type: text/markdown
10
10
 
11
11
  # vercel-internal-core-bundle
@@ -26,3 +26,14 @@ public session context from `vercel.api` and shared exceptions from
26
26
  from vercel.api import session
27
27
  from vercel.errors import VercelError
28
28
  ```
29
+
30
+ ## Legacy HTTPX client migration
31
+
32
+ HTTPX2 is the default HTTP implementation and the only HTTPX family installed
33
+ by the SDK. As a temporary runtime-only migration path, applications that
34
+ explicitly install legacy `httpx` may return a complete `httpx.Client` or
35
+ `httpx.AsyncClient` from `session(httpx_client_factory=...)`. Static annotations
36
+ remain HTTPX2-based, so type-checked applications need a targeted `cast(Any, ...)`.
37
+
38
+ Legacy transport objects must remain inside a legacy client; an
39
+ `httpx.HTTPTransport` cannot be mounted in an `httpx2.Client`.
@@ -16,3 +16,14 @@ public session context from `vercel.api` and shared exceptions from
16
16
  from vercel.api import session
17
17
  from vercel.errors import VercelError
18
18
  ```
19
+
20
+ ## Legacy HTTPX client migration
21
+
22
+ HTTPX2 is the default HTTP implementation and the only HTTPX family installed
23
+ by the SDK. As a temporary runtime-only migration path, applications that
24
+ explicitly install legacy `httpx` may return a complete `httpx.Client` or
25
+ `httpx.AsyncClient` from `session(httpx_client_factory=...)`. Static annotations
26
+ remain HTTPX2-based, so type-checked applications need a targeted `cast(Any, ...)`.
27
+
28
+ Legacy transport objects must remain inside a legacy client; an
29
+ `httpx.HTTPTransport` cannot be mounted in an `httpx2.Client`.
@@ -20,7 +20,7 @@ path = "hatch_build.py"
20
20
 
21
21
  [tool.vercel.release.dependencies]
22
22
  dependencies = [
23
- "vercel-internal-shared-vendored-deps>=0.1.1",
23
+ "vercel-internal-shared-vendored-deps>=0.1.2",
24
24
  ]
25
25
 
26
26
  [tool.hatch.version]
@@ -55,7 +55,7 @@ exclude = [
55
55
 
56
56
  [tool.pytest.ini_options]
57
57
  testpaths = ["tests"]
58
- pythonpath = ["."]
58
+ pythonpath = [".", "../.."]
59
59
  addopts = "--no-header --capture=tee-sys"
60
60
  asyncio_mode = "auto"
61
61
 
@@ -9,7 +9,6 @@ appropriate.
9
9
 
10
10
  import inspect
11
11
  import io
12
- import sys
13
12
  import tempfile
14
13
  from collections.abc import AsyncIterator
15
14
  from contextlib import AbstractAsyncContextManager, asynccontextmanager
@@ -17,10 +16,7 @@ from typing import Protocol, TypeAlias, cast
17
16
 
18
17
  from vercel.internal._vendor import anyio
19
18
 
20
- if sys.version_info >= (3, 12):
21
- from collections.abc import Buffer
22
- else:
23
- from vercel.internal._vendor.typing_extensions import Buffer
19
+ from vercel._internal.core.polyfills import Buffer
24
20
 
25
21
 
26
22
  class SyncByteReader(Protocol):
@@ -10,6 +10,7 @@ from vercel._internal.core.http.retry import (
10
10
  SleepFn,
11
11
  )
12
12
  from vercel._internal.core.http.transport import (
13
+ NO_TIMEOUT,
13
14
  AsyncTransport,
14
15
  BaseTransport,
15
16
  BytesBody,
@@ -17,6 +18,7 @@ from vercel._internal.core.http.transport import (
17
18
  RawBody,
18
19
  ReadResponsePolicy,
19
20
  RequestBody,
21
+ RequestTimeout,
20
22
  StreamingRequest,
21
23
  StreamingResponse,
22
24
  SyncTransport,
@@ -33,9 +35,11 @@ __all__ = [
33
35
  "TransportOptions",
34
36
  "JSONBody",
35
37
  "BytesBody",
38
+ "NO_TIMEOUT",
36
39
  "RawBody",
37
40
  "ReadResponsePolicy",
38
41
  "RequestBody",
42
+ "RequestTimeout",
39
43
  "StreamingRequest",
40
44
  "StreamingResponse",
41
45
  "RetryPolicy",
@@ -0,0 +1,61 @@
1
+ """Runtime compatibility helpers for HTTPX client families."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import sys
6
+ from typing import Any, Protocol, TypeVar, cast
7
+
8
+ from vercel.internal._vendor import httpx2
9
+
10
+ _ExceptionT = TypeVar("_ExceptionT", bound=BaseException)
11
+
12
+
13
+ class _LegacyHttpxModule(Protocol):
14
+ Client: type[Any]
15
+ AsyncClient: type[Any]
16
+
17
+
18
+ def _loaded_legacy_httpx() -> _LegacyHttpxModule | None:
19
+ """Return legacy HTTPX only when the application already imported it."""
20
+ module = sys.modules.get("httpx")
21
+ return cast(_LegacyHttpxModule, module) if module is not None else None
22
+
23
+
24
+ def is_sync_http_client(value: object) -> bool:
25
+ if isinstance(value, httpx2.Client):
26
+ return True
27
+ module = _loaded_legacy_httpx()
28
+ return module is not None and isinstance(value, module.Client)
29
+
30
+
31
+ def is_async_http_client(value: object) -> bool:
32
+ if isinstance(value, httpx2.AsyncClient):
33
+ return True
34
+ module = _loaded_legacy_httpx()
35
+ return module is not None and isinstance(value, module.AsyncClient)
36
+
37
+
38
+ def _exception_types(primary: type[_ExceptionT], legacy_name: str) -> tuple[type[_ExceptionT], ...]:
39
+ module = _loaded_legacy_httpx()
40
+ if module is None:
41
+ return (primary,)
42
+ legacy = getattr(module, legacy_name, None)
43
+ if not isinstance(legacy, type) or not issubclass(legacy, BaseException):
44
+ return (primary,)
45
+ return (primary, cast(type[_ExceptionT], legacy))
46
+
47
+
48
+ def transport_errors() -> tuple[type[httpx2.TransportError], ...]:
49
+ return _exception_types(httpx2.TransportError, "TransportError")
50
+
51
+
52
+ def http_errors() -> tuple[type[httpx2.HTTPError], ...]:
53
+ return _exception_types(httpx2.HTTPError, "HTTPError")
54
+
55
+
56
+ def http_status_errors() -> tuple[type[httpx2.HTTPStatusError], ...]:
57
+ return _exception_types(httpx2.HTTPStatusError, "HTTPStatusError")
58
+
59
+
60
+ def response_not_read_errors() -> tuple[type[httpx2.ResponseNotRead], ...]:
61
+ return _exception_types(httpx2.ResponseNotRead, "ResponseNotRead")
@@ -4,7 +4,7 @@ from __future__ import annotations
4
4
 
5
5
  from typing import TypedDict
6
6
 
7
- from vercel.internal._vendor import httpx
7
+ import vercel.internal._vendor.httpx2 as httpx
8
8
 
9
9
  from vercel._internal.core.http.transport import TransportOptions
10
10
  from vercel._internal.core.time import to_seconds_float
@@ -1,7 +1,7 @@
1
1
  from collections.abc import Awaitable, Callable
2
2
  from dataclasses import dataclass
3
3
 
4
- from vercel.internal._vendor import httpx
4
+ import vercel.internal._vendor.httpx2 as httpx
5
5
 
6
6
  SleepFn = Callable[[float], Awaitable[None] | None]
7
7
 
@@ -11,13 +11,13 @@ from contextlib import AbstractAsyncContextManager, asynccontextmanager
11
11
  from dataclasses import dataclass
12
12
  from datetime import timedelta
13
13
  from types import TracebackType
14
- from typing import Any, TypeAlias
14
+ from typing import Any, Final, TypeAlias, cast, final
15
15
 
16
16
  from vercel.internal._vendor import anyio
17
- from vercel.internal._vendor import httpx
17
+ import vercel.internal._vendor.httpx2 as httpx
18
18
  from vercel.internal._vendor.anyio.abc import ObjectReceiveStream, ObjectSendStream
19
- from vercel.internal._vendor.httpx import USE_CLIENT_DEFAULT
20
19
 
20
+ from vercel._internal.core.http._compat import is_async_http_client
21
21
  from vercel._internal.core.polyfills import StrEnum
22
22
  from vercel._internal.core.time import to_seconds_float
23
23
 
@@ -64,6 +64,17 @@ class RawBody:
64
64
  RequestBody = JSONBody | BytesBody | RawBody | None
65
65
 
66
66
 
67
+ @final
68
+ class _NoTimeout:
69
+ """Select no HTTPX timeout instead of inheriting the client default."""
70
+
71
+ __slots__ = ()
72
+
73
+
74
+ NO_TIMEOUT: Final = _NoTimeout()
75
+ RequestTimeout: TypeAlias = timedelta | _NoTimeout | None
76
+
77
+
67
78
  class ReadResponsePolicy(StrEnum):
68
79
  ALWAYS = "always"
69
80
  NON_SUCCESS_ONLY = "non_success_only"
@@ -89,7 +100,7 @@ class BaseTransport(abc.ABC):
89
100
  params: QueryParamTypes | None = None,
90
101
  body: RequestBody = None,
91
102
  headers: HeaderTypes | None = None,
92
- timeout: timedelta | None = None,
103
+ timeout: RequestTimeout = None,
93
104
  follow_redirects: bool | None = None,
94
105
  stream: bool = False,
95
106
  read_response: ReadResponsePolicy = ReadResponsePolicy.NEVER,
@@ -104,7 +115,7 @@ class BaseTransport(abc.ABC):
104
115
  token: str | None = None,
105
116
  params: QueryParamTypes | None = None,
106
117
  headers: HeaderTypes | None = None,
107
- timeout: timedelta | None = None,
118
+ timeout: RequestTimeout = None,
108
119
  follow_redirects: bool | None = None,
109
120
  read_response: ReadResponsePolicy = ReadResponsePolicy.NON_SUCCESS_ONLY,
110
121
  response_chunk_size: int | None = None,
@@ -121,7 +132,7 @@ class BaseTransport(abc.ABC):
121
132
  params: QueryParamTypes | None = None,
122
133
  body: RequestBody = None,
123
134
  headers: HeaderTypes | None = None,
124
- timeout: timedelta | None = None,
135
+ timeout: RequestTimeout = None,
125
136
  follow_redirects: bool | None = None,
126
137
  read_response: ReadResponsePolicy = ReadResponsePolicy.NON_SUCCESS_ONLY,
127
138
  chunk_size: int | None = None,
@@ -139,7 +150,7 @@ class BaseTransport(abc.ABC):
139
150
  params: QueryParamTypes | None = None,
140
151
  body: RequestBody = None,
141
152
  headers: HeaderTypes | None = None,
142
- timeout: timedelta | None = None,
153
+ timeout: RequestTimeout = None,
143
154
  ) -> httpx.Request:
144
155
  headers = httpx.Headers(headers)
145
156
  if token is not None:
@@ -156,12 +167,23 @@ class BaseTransport(abc.ABC):
156
167
  case RawBody():
157
168
  content = body.data
158
169
 
159
- if timeout is not None:
170
+ if timeout is NO_TIMEOUT:
160
171
  return client.build_request(
161
172
  method,
162
173
  _normalize_path(path),
163
174
  params=params,
164
- timeout=httpx.Timeout(to_seconds_float(timeout)),
175
+ timeout=None,
176
+ headers=headers,
177
+ json=json,
178
+ content=content,
179
+ )
180
+
181
+ if isinstance(timeout, timedelta):
182
+ return client.build_request(
183
+ method,
184
+ _normalize_path(path),
185
+ params=params,
186
+ timeout=to_seconds_float(timeout),
165
187
  headers=headers,
166
188
  json=json,
167
189
  content=content,
@@ -289,13 +311,14 @@ class _SyncStreamingRequest(StreamingRequest):
289
311
  def _run(self) -> None:
290
312
  response: httpx.Response | None = None
291
313
  try:
292
- response = self._client.send(
293
- self._request,
294
- stream=True,
295
- follow_redirects=self._follow_redirects
296
- if self._follow_redirects is not None
297
- else USE_CLIENT_DEFAULT,
298
- )
314
+ if self._follow_redirects is None:
315
+ response = self._client.send(self._request, stream=True)
316
+ else:
317
+ response = self._client.send(
318
+ self._request,
319
+ stream=True,
320
+ follow_redirects=self._follow_redirects,
321
+ )
299
322
  _read_sync_response(response, self._read_response)
300
323
  self._response = response
301
324
  except _RequestStreamAborted:
@@ -458,13 +481,14 @@ class _AsyncStreamingRequest(StreamingRequest):
458
481
  if self._aborted:
459
482
  cancel_scope.cancel()
460
483
  else:
461
- response = await self._client.send(
462
- self._request,
463
- stream=True,
464
- follow_redirects=self._follow_redirects
465
- if self._follow_redirects is not None
466
- else USE_CLIENT_DEFAULT,
467
- )
484
+ if self._follow_redirects is None:
485
+ response = await self._client.send(self._request, stream=True)
486
+ else:
487
+ response = await self._client.send(
488
+ self._request,
489
+ stream=True,
490
+ follow_redirects=self._follow_redirects,
491
+ )
468
492
  await _read_async_response(response, self._read_response)
469
493
  self._response = response
470
494
  if self._aborted and response is not None and self._response is None:
@@ -604,7 +628,7 @@ class SyncTransport(BaseTransport):
604
628
  params: QueryParamTypes | None = None,
605
629
  body: RequestBody = None,
606
630
  headers: HeaderTypes | None = None,
607
- timeout: timedelta | None = None,
631
+ timeout: RequestTimeout = None,
608
632
  follow_redirects: bool | None = None,
609
633
  stream: bool = False,
610
634
  read_response: ReadResponsePolicy = ReadResponsePolicy.NEVER,
@@ -619,13 +643,14 @@ class SyncTransport(BaseTransport):
619
643
  headers=headers,
620
644
  timeout=timeout,
621
645
  )
622
- response = self._client.send(
623
- request,
624
- stream=stream,
625
- follow_redirects=follow_redirects
626
- if follow_redirects is not None
627
- else USE_CLIENT_DEFAULT,
628
- )
646
+ if follow_redirects is None:
647
+ response = self._client.send(request, stream=stream)
648
+ else:
649
+ response = self._client.send(
650
+ request,
651
+ stream=stream,
652
+ follow_redirects=follow_redirects,
653
+ )
629
654
  _read_sync_response(response, read_response)
630
655
  return response
631
656
 
@@ -638,7 +663,7 @@ class SyncTransport(BaseTransport):
638
663
  token: str | None = None,
639
664
  params: QueryParamTypes | None = None,
640
665
  headers: HeaderTypes | None = None,
641
- timeout: timedelta | None = None,
666
+ timeout: RequestTimeout = None,
642
667
  follow_redirects: bool | None = None,
643
668
  read_response: ReadResponsePolicy = ReadResponsePolicy.NON_SUCCESS_ONLY,
644
669
  response_chunk_size: int | None = None,
@@ -683,7 +708,7 @@ class SyncTransport(BaseTransport):
683
708
  params: QueryParamTypes | None = None,
684
709
  body: RequestBody = None,
685
710
  headers: HeaderTypes | None = None,
686
- timeout: timedelta | None = None,
711
+ timeout: RequestTimeout = None,
687
712
  follow_redirects: bool | None = None,
688
713
  read_response: ReadResponsePolicy = ReadResponsePolicy.NON_SUCCESS_ONLY,
689
714
  chunk_size: int | None = None,
@@ -725,9 +750,10 @@ class AsyncTransport(BaseTransport):
725
750
  that outlives a loop passes a callable and gets a client per loop. The
726
751
  transport object itself is memoized by callers and cannot be swapped out.
727
752
  """
728
- self._resolve_client: Callable[[], httpx.AsyncClient] = (
729
- (lambda: client) if isinstance(client, httpx.AsyncClient) else client
730
- )
753
+ if is_async_http_client(client):
754
+ self._resolve_client = lambda: cast(httpx.AsyncClient, client)
755
+ else:
756
+ self._resolve_client = cast(Callable[[], httpx.AsyncClient], client)
731
757
  # Resolved once here so a factory that yields the wrong kind of client
732
758
  # fails when the transport is built, as it did before.
733
759
  self._resolve_client()
@@ -741,7 +767,7 @@ class AsyncTransport(BaseTransport):
741
767
  params: QueryParamTypes | None = None,
742
768
  body: RequestBody = None,
743
769
  headers: HeaderTypes | None = None,
744
- timeout: timedelta | None = None,
770
+ timeout: RequestTimeout = None,
745
771
  follow_redirects: bool | None = None,
746
772
  stream: bool = False,
747
773
  read_response: ReadResponsePolicy = ReadResponsePolicy.NEVER,
@@ -757,13 +783,14 @@ class AsyncTransport(BaseTransport):
757
783
  headers=headers,
758
784
  timeout=timeout,
759
785
  )
760
- response = await client.send(
761
- request,
762
- stream=stream,
763
- follow_redirects=follow_redirects
764
- if follow_redirects is not None
765
- else USE_CLIENT_DEFAULT,
766
- )
786
+ if follow_redirects is None:
787
+ response = await client.send(request, stream=stream)
788
+ else:
789
+ response = await client.send(
790
+ request,
791
+ stream=stream,
792
+ follow_redirects=follow_redirects,
793
+ )
767
794
  await _read_async_response(response, read_response)
768
795
  return response
769
796
 
@@ -776,7 +803,7 @@ class AsyncTransport(BaseTransport):
776
803
  token: str | None = None,
777
804
  params: QueryParamTypes | None = None,
778
805
  headers: HeaderTypes | None = None,
779
- timeout: timedelta | None = None,
806
+ timeout: RequestTimeout = None,
780
807
  follow_redirects: bool | None = None,
781
808
  read_response: ReadResponsePolicy = ReadResponsePolicy.NON_SUCCESS_ONLY,
782
809
  response_chunk_size: int | None = None,
@@ -838,7 +865,7 @@ class AsyncTransport(BaseTransport):
838
865
  params: QueryParamTypes | None = None,
839
866
  body: RequestBody = None,
840
867
  headers: HeaderTypes | None = None,
841
- timeout: timedelta | None = None,
868
+ timeout: RequestTimeout = None,
842
869
  follow_redirects: bool | None = None,
843
870
  read_response: ReadResponsePolicy = ReadResponsePolicy.NON_SUCCESS_ONLY,
844
871
  chunk_size: int | None = None,
@@ -4,6 +4,6 @@ Polyfills for modern Python features used by internal core.
4
4
 
5
5
  from ._datetime import UTC
6
6
  from ._strenum import StrEnum
7
- from ._typing import Self
7
+ from ._typing import Buffer, Self
8
8
 
9
- __all__ = ("Self", "StrEnum", "UTC")
9
+ __all__ = ("Buffer", "Self", "StrEnum", "UTC")
@@ -0,0 +1,13 @@
1
+ import sys
2
+
3
+ if sys.version_info >= (3, 12):
4
+ from collections.abc import Buffer
5
+ else:
6
+ from vercel.internal._vendor.typing_extensions import Buffer
7
+
8
+ if sys.version_info >= (3, 11):
9
+ from typing import Self
10
+ else:
11
+ from vercel.internal._vendor.typing_extensions import Self
12
+
13
+ __all__ = ("Buffer", "Self")
@@ -6,16 +6,20 @@ import time
6
6
  from collections.abc import Callable, Mapping, Sequence
7
7
  from contextvars import ContextVar, Token
8
8
  from types import TracebackType
9
- from typing import TYPE_CHECKING, ClassVar, TypeVar, cast, overload
9
+ from typing import TYPE_CHECKING, Any, ClassVar, TypeVar, cast, overload
10
10
 
11
11
  from vercel.internal._vendor import anyio
12
- from vercel.internal._vendor import httpx
12
+ import vercel.internal._vendor.httpx2 as httpx
13
13
 
14
14
  from vercel._internal.core.errors import (
15
15
  VercelServiceOptionsError,
16
16
  VercelSessionClosedError,
17
17
  VercelSessionError,
18
18
  )
19
+ from vercel._internal.core.http._compat import (
20
+ is_async_http_client,
21
+ is_sync_http_client,
22
+ )
19
23
  from vercel._internal.core.options import ServiceOptions, merge_service_options
20
24
  from vercel._internal.core.polyfills import Self
21
25
 
@@ -197,17 +201,18 @@ class SdkSession(_BaseSdkSession):
197
201
  )
198
202
  )
199
203
  else:
200
- candidate = self._httpx_client_factory()
201
- if not isinstance(candidate, httpx.AsyncClient):
202
- if isinstance(candidate, httpx.Client):
204
+ candidate = cast(Any, self._httpx_client_factory())
205
+ if not is_async_http_client(candidate):
206
+ if is_sync_http_client(candidate):
203
207
  try:
204
208
  candidate.close()
205
209
  except Exception:
206
210
  pass
207
211
  raise VercelSessionError(
208
- "Async SDK sessions require httpx_client_factory to return httpx.AsyncClient"
212
+ "Async SDK sessions require httpx_client_factory to return "
213
+ "httpx2.AsyncClient or httpx.AsyncClient"
209
214
  )
210
- client = candidate
215
+ client = cast(httpx.AsyncClient, candidate)
211
216
  return client
212
217
 
213
218
  def get_transport(self) -> "AsyncTransport":
@@ -294,7 +299,7 @@ class SyncSdkSession(_BaseSdkSession):
294
299
  ),
295
300
  )
296
301
 
297
- def _close_wrong_async_client(self, client: httpx.AsyncClient) -> None:
302
+ def _close_wrong_async_client(self, client: Any) -> None:
298
303
  try:
299
304
  loop = asyncio.get_running_loop()
300
305
  except RuntimeError:
@@ -327,14 +332,15 @@ class SyncSdkSession(_BaseSdkSession):
327
332
  )
328
333
  )
329
334
  else:
330
- candidate = self._httpx_client_factory()
331
- if not isinstance(candidate, httpx.Client):
332
- if isinstance(candidate, httpx.AsyncClient):
335
+ candidate = cast(Any, self._httpx_client_factory())
336
+ if not is_sync_http_client(candidate):
337
+ if is_async_http_client(candidate):
333
338
  self._close_wrong_async_client(candidate)
334
339
  raise VercelSessionError(
335
- "Sync SDK sessions require httpx_client_factory to return httpx.Client"
340
+ "Sync SDK sessions require httpx_client_factory to return "
341
+ "httpx2.Client or httpx.Client"
336
342
  )
337
- client = candidate
343
+ client = cast(httpx.Client, candidate)
338
344
  self._transport = SyncTransport(client)
339
345
  return self._transport
340
346
 
@@ -0,0 +1 @@
1
+ __version__ = "0.2.0"
@@ -1,8 +0,0 @@
1
- import sys
2
-
3
- if sys.version_info >= (3, 11):
4
- from typing import Self
5
- else:
6
- from vercel.internal._vendor.typing_extensions import Self
7
-
8
- __all__ = ("Self",)
@@ -1 +0,0 @@
1
- __version__ = "0.1.2"