Skip to content

Commit 1a0d221

Browse files
chore(internal): codegen related update
1 parent fac7409 commit 1a0d221

23 files changed

+259
-60
lines changed

README.md

+3-4
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ except openlayer.APIStatusError as e:
172172
print(e.response)
173173
```
174174

175-
Error codes are as followed:
175+
Error codes are as follows:
176176

177177
| Status Code | Error Type |
178178
| ----------- | -------------------------- |
@@ -373,8 +373,7 @@ If you need to access undocumented endpoints, params, or response properties, th
373373
#### Undocumented endpoints
374374

375375
To make requests to undocumented endpoints, you can make requests using `client.get`, `client.post`, and other
376-
http verbs. Options on the client will be respected (such as retries) will be respected when making this
377-
request.
376+
http verbs. Options on the client will be respected (such as retries) when making this request.
378377

379378
```py
380379
import httpx
@@ -446,7 +445,7 @@ with Openlayer() as client:
446445
This package generally follows [SemVer](https://semver.org/spec/v2.0.0.html) conventions, though certain backwards-incompatible changes may be released as minor versions:
447446

448447
1. Changes that only affect static types, without breaking runtime behavior.
449-
2. Changes to library internals which are technically public but not intended or documented for external use. _(Please open a GitHub issue to let us know if you are relying on such internals)_.
448+
2. Changes to library internals which are technically public but not intended or documented for external use. _(Please open a GitHub issue to let us know if you are relying on such internals.)_
450449
3. Changes that we do not expect to impact the vast majority of users in practice.
451450

452451
We take backwards-compatibility seriously and work hard to ensure you can rely on a smooth upgrade experience.

mypy.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ cache_fine_grained = True
4141
# ```
4242
# Changing this codegen to make mypy happy would increase complexity
4343
# and would not be worth it.
44-
disable_error_code = func-returns-value
44+
disable_error_code = func-returns-value,overload-cannot-match
4545

4646
# https://github.com/python/mypy/issues/12162
4747
[mypy.overrides]

pyproject.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ dev-dependencies = [
5959
"dirty-equals>=0.6.0",
6060
"importlib-metadata>=6.7.0",
6161
"rich>=13.7.1",
62-
"nest_asyncio==1.6.0"
62+
"nest_asyncio==1.6.0",
6363
]
6464

6565
[tool.rye.scripts]
@@ -134,6 +134,7 @@ testpaths = ["tests"]
134134
addopts = "--tb=short"
135135
xfail_strict = true
136136
asyncio_mode = "auto"
137+
asyncio_default_fixture_loop_scope = "session"
137138
filterwarnings = [
138139
"error"
139140
]

requirements-dev.lock

+4-5
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ h11==0.14.0
3838
# via httpcore
3939
httpcore==1.0.2
4040
# via httpx
41-
httpx==0.25.2
41+
httpx==0.28.1
4242
# via openlayer
4343
# via respx
4444
idna==3.4
@@ -52,7 +52,7 @@ markdown-it-py==3.0.0
5252
# via rich
5353
mdurl==0.1.2
5454
# via markdown-it-py
55-
mypy==1.13.0
55+
mypy==1.14.1
5656
mypy-extensions==1.0.0
5757
# via mypy
5858
nest-asyncio==1.6.0
@@ -80,7 +80,7 @@ pydantic-core==2.27.1
8080
# via pydantic
8181
pygments==2.18.0
8282
# via rich
83-
pyright==1.1.390
83+
pyright==1.1.392.post0
8484
pytest==8.3.3
8585
# via pytest-asyncio
8686
pytest-asyncio==0.24.0
@@ -96,7 +96,7 @@ requests==2.32.3
9696
# via requests-toolbelt
9797
requests-toolbelt==1.0.0
9898
# via openlayer
99-
respx==0.20.2
99+
respx==0.22.0
100100
rich==13.7.1
101101
ruff==0.6.9
102102
setuptools==68.2.2
@@ -105,7 +105,6 @@ six==1.16.0
105105
# via python-dateutil
106106
sniffio==1.3.0
107107
# via anyio
108-
# via httpx
109108
# via openlayer
110109
time-machine==2.9.0
111110
tomli==2.0.2

requirements.lock

+1-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ h11==0.14.0
2828
# via httpcore
2929
httpcore==1.0.2
3030
# via httpx
31-
httpx==0.25.2
31+
httpx==0.28.1
3232
# via openlayer
3333
idna==3.4
3434
# via anyio
@@ -60,7 +60,6 @@ six==1.16.0
6060
# via python-dateutil
6161
sniffio==1.3.0
6262
# via anyio
63-
# via httpx
6463
# via openlayer
6564
tqdm==4.67.1
6665
# via openlayer

src/openlayer/_base_client.py

+6
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,9 @@ def __init__(self, **kwargs: Any) -> None:
754754

755755
class SyncHttpxClientWrapper(DefaultHttpxClient):
756756
def __del__(self) -> None:
757+
if self.is_closed:
758+
return
759+
757760
try:
758761
self.close()
759762
except Exception:
@@ -1280,6 +1283,9 @@ def __init__(self, **kwargs: Any) -> None:
12801283

12811284
class AsyncHttpxClientWrapper(DefaultAsyncHttpxClient):
12821285
def __del__(self) -> None:
1286+
if self.is_closed:
1287+
return
1288+
12831289
try:
12841290
# TODO(someday): support non asyncio runtimes here
12851291
asyncio.get_running_loop().create_task(self.aclose())

src/openlayer/_models.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -179,14 +179,14 @@ def __str__(self) -> str:
179179
@classmethod
180180
@override
181181
def construct( # pyright: ignore[reportIncompatibleMethodOverride]
182-
cls: Type[ModelT],
182+
__cls: Type[ModelT],
183183
_fields_set: set[str] | None = None,
184184
**values: object,
185185
) -> ModelT:
186-
m = cls.__new__(cls)
186+
m = __cls.__new__(__cls)
187187
fields_values: dict[str, object] = {}
188188

189-
config = get_model_config(cls)
189+
config = get_model_config(__cls)
190190
populate_by_name = (
191191
config.allow_population_by_field_name
192192
if isinstance(config, _ConfigProtocol)
@@ -196,7 +196,7 @@ def construct( # pyright: ignore[reportIncompatibleMethodOverride]
196196
if _fields_set is None:
197197
_fields_set = set()
198198

199-
model_fields = get_model_fields(cls)
199+
model_fields = get_model_fields(__cls)
200200
for name, field in model_fields.items():
201201
key = field.alias
202202
if key is None or (key not in values and populate_by_name):
@@ -488,7 +488,11 @@ def construct_type(*, value: object, type_: object) -> object:
488488
_, items_type = get_args(type_) # Dict[_, items_type]
489489
return {key: construct_type(value=item, type_=items_type) for key, item in value.items()}
490490

491-
if not is_literal_type(type_) and (issubclass(origin, BaseModel) or issubclass(origin, GenericModel)):
491+
if (
492+
not is_literal_type(type_)
493+
and inspect.isclass(origin)
494+
and (issubclass(origin, BaseModel) or issubclass(origin, GenericModel))
495+
):
492496
if is_list(value):
493497
return [cast(Any, type_).construct(**entry) if is_mapping(entry) else entry for entry in value]
494498

src/openlayer/_response.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ def _parse(self, *, to: type[_T] | None = None) -> R | _T:
136136
if cast_to and is_annotated_type(cast_to):
137137
cast_to = extract_type_arg(cast_to, 0)
138138

139+
origin = get_origin(cast_to) or cast_to
140+
139141
if self._is_sse_stream:
140142
if to:
141143
if not is_stream_class_type(to):
@@ -195,8 +197,6 @@ def _parse(self, *, to: type[_T] | None = None) -> R | _T:
195197
if cast_to == bool:
196198
return cast(R, response.text.lower() == "true")
197199

198-
origin = get_origin(cast_to) or cast_to
199-
200200
if origin == APIResponse:
201201
raise RuntimeError("Unexpected state - cast_to is `APIResponse`")
202202

@@ -210,7 +210,13 @@ def _parse(self, *, to: type[_T] | None = None) -> R | _T:
210210
raise ValueError(f"Subclasses of httpx.Response cannot be passed to `cast_to`")
211211
return cast(R, response)
212212

213-
if inspect.isclass(origin) and not issubclass(origin, BaseModel) and issubclass(origin, pydantic.BaseModel):
213+
if (
214+
inspect.isclass(
215+
origin # pyright: ignore[reportUnknownArgumentType]
216+
)
217+
and not issubclass(origin, BaseModel)
218+
and issubclass(origin, pydantic.BaseModel)
219+
):
214220
raise TypeError("Pydantic models must subclass our base model type, e.g. `from openlayer import BaseModel`")
215221

216222
if (

src/openlayer/resources/commits/commits.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def test_results(self) -> TestResultsResource:
3535
@cached_property
3636
def with_raw_response(self) -> CommitsResourceWithRawResponse:
3737
"""
38-
This property can be used as a prefix for any HTTP method call to return the
38+
This property can be used as a prefix for any HTTP method call to return
3939
the raw response object instead of the parsed content.
4040
4141
For more information, see https://www.github.com/openlayer-ai/openlayer-python#accessing-raw-response-data-eg-headers
@@ -93,7 +93,7 @@ def test_results(self) -> AsyncTestResultsResource:
9393
@cached_property
9494
def with_raw_response(self) -> AsyncCommitsResourceWithRawResponse:
9595
"""
96-
This property can be used as a prefix for any HTTP method call to return the
96+
This property can be used as a prefix for any HTTP method call to return
9797
the raw response object instead of the parsed content.
9898
9999
For more information, see https://www.github.com/openlayer-ai/openlayer-python#accessing-raw-response-data-eg-headers

src/openlayer/resources/commits/test_results.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class TestResultsResource(SyncAPIResource):
3232
@cached_property
3333
def with_raw_response(self) -> TestResultsResourceWithRawResponse:
3434
"""
35-
This property can be used as a prefix for any HTTP method call to return the
35+
This property can be used as a prefix for any HTTP method call to return
3636
the raw response object instead of the parsed content.
3737
3838
For more information, see https://www.github.com/openlayer-ai/openlayer-python#accessing-raw-response-data-eg-headers
@@ -116,7 +116,7 @@ class AsyncTestResultsResource(AsyncAPIResource):
116116
@cached_property
117117
def with_raw_response(self) -> AsyncTestResultsResourceWithRawResponse:
118118
"""
119-
This property can be used as a prefix for any HTTP method call to return the
119+
This property can be used as a prefix for any HTTP method call to return
120120
the raw response object instead of the parsed content.
121121
122122
For more information, see https://www.github.com/openlayer-ai/openlayer-python#accessing-raw-response-data-eg-headers

src/openlayer/resources/inference_pipelines/data.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class DataResource(SyncAPIResource):
3030
@cached_property
3131
def with_raw_response(self) -> DataResourceWithRawResponse:
3232
"""
33-
This property can be used as a prefix for any HTTP method call to return the
33+
This property can be used as a prefix for any HTTP method call to return
3434
the raw response object instead of the parsed content.
3535
3636
For more information, see https://www.github.com/openlayer-ai/openlayer-python#accessing-raw-response-data-eg-headers
@@ -100,7 +100,7 @@ class AsyncDataResource(AsyncAPIResource):
100100
@cached_property
101101
def with_raw_response(self) -> AsyncDataResourceWithRawResponse:
102102
"""
103-
This property can be used as a prefix for any HTTP method call to return the
103+
This property can be used as a prefix for any HTTP method call to return
104104
the raw response object instead of the parsed content.
105105
106106
For more information, see https://www.github.com/openlayer-ai/openlayer-python#accessing-raw-response-data-eg-headers

src/openlayer/resources/inference_pipelines/inference_pipelines.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def test_results(self) -> TestResultsResource:
6868
@cached_property
6969
def with_raw_response(self) -> InferencePipelinesResourceWithRawResponse:
7070
"""
71-
This property can be used as a prefix for any HTTP method call to return the
71+
This property can be used as a prefix for any HTTP method call to return
7272
the raw response object instead of the parsed content.
7373
7474
For more information, see https://www.github.com/openlayer-ai/openlayer-python#accessing-raw-response-data-eg-headers
@@ -234,7 +234,7 @@ def test_results(self) -> AsyncTestResultsResource:
234234
@cached_property
235235
def with_raw_response(self) -> AsyncInferencePipelinesResourceWithRawResponse:
236236
"""
237-
This property can be used as a prefix for any HTTP method call to return the
237+
This property can be used as a prefix for any HTTP method call to return
238238
the raw response object instead of the parsed content.
239239
240240
For more information, see https://www.github.com/openlayer-ai/openlayer-python#accessing-raw-response-data-eg-headers

src/openlayer/resources/inference_pipelines/rows.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class RowsResource(SyncAPIResource):
3030
@cached_property
3131
def with_raw_response(self) -> RowsResourceWithRawResponse:
3232
"""
33-
This property can be used as a prefix for any HTTP method call to return the
33+
This property can be used as a prefix for any HTTP method call to return
3434
the raw response object instead of the parsed content.
3535
3636
For more information, see https://www.github.com/openlayer-ai/openlayer-python#accessing-raw-response-data-eg-headers
@@ -102,7 +102,7 @@ class AsyncRowsResource(AsyncAPIResource):
102102
@cached_property
103103
def with_raw_response(self) -> AsyncRowsResourceWithRawResponse:
104104
"""
105-
This property can be used as a prefix for any HTTP method call to return the
105+
This property can be used as a prefix for any HTTP method call to return
106106
the raw response object instead of the parsed content.
107107
108108
For more information, see https://www.github.com/openlayer-ai/openlayer-python#accessing-raw-response-data-eg-headers

src/openlayer/resources/inference_pipelines/test_results.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class TestResultsResource(SyncAPIResource):
3232
@cached_property
3333
def with_raw_response(self) -> TestResultsResourceWithRawResponse:
3434
"""
35-
This property can be used as a prefix for any HTTP method call to return the
35+
This property can be used as a prefix for any HTTP method call to return
3636
the raw response object instead of the parsed content.
3737
3838
For more information, see https://www.github.com/openlayer-ai/openlayer-python#accessing-raw-response-data-eg-headers
@@ -114,7 +114,7 @@ class AsyncTestResultsResource(AsyncAPIResource):
114114
@cached_property
115115
def with_raw_response(self) -> AsyncTestResultsResourceWithRawResponse:
116116
"""
117-
This property can be used as a prefix for any HTTP method call to return the
117+
This property can be used as a prefix for any HTTP method call to return
118118
the raw response object instead of the parsed content.
119119
120120
For more information, see https://www.github.com/openlayer-ai/openlayer-python#accessing-raw-response-data-eg-headers

src/openlayer/resources/projects/commits.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class CommitsResource(SyncAPIResource):
3131
@cached_property
3232
def with_raw_response(self) -> CommitsResourceWithRawResponse:
3333
"""
34-
This property can be used as a prefix for any HTTP method call to return the
34+
This property can be used as a prefix for any HTTP method call to return
3535
the raw response object instead of the parsed content.
3636
3737
For more information, see https://www.github.com/openlayer-ai/openlayer-python#accessing-raw-response-data-eg-headers
@@ -155,7 +155,7 @@ class AsyncCommitsResource(AsyncAPIResource):
155155
@cached_property
156156
def with_raw_response(self) -> AsyncCommitsResourceWithRawResponse:
157157
"""
158-
This property can be used as a prefix for any HTTP method call to return the
158+
This property can be used as a prefix for any HTTP method call to return
159159
the raw response object instead of the parsed content.
160160
161161
For more information, see https://www.github.com/openlayer-ai/openlayer-python#accessing-raw-response-data-eg-headers

src/openlayer/resources/projects/inference_pipelines.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class InferencePipelinesResource(SyncAPIResource):
3131
@cached_property
3232
def with_raw_response(self) -> InferencePipelinesResourceWithRawResponse:
3333
"""
34-
This property can be used as a prefix for any HTTP method call to return the
34+
This property can be used as a prefix for any HTTP method call to return
3535
the raw response object instead of the parsed content.
3636
3737
For more information, see https://www.github.com/openlayer-ai/openlayer-python#accessing-raw-response-data-eg-headers
@@ -155,7 +155,7 @@ class AsyncInferencePipelinesResource(AsyncAPIResource):
155155
@cached_property
156156
def with_raw_response(self) -> AsyncInferencePipelinesResourceWithRawResponse:
157157
"""
158-
This property can be used as a prefix for any HTTP method call to return the
158+
This property can be used as a prefix for any HTTP method call to return
159159
the raw response object instead of the parsed content.
160160
161161
For more information, see https://www.github.com/openlayer-ai/openlayer-python#accessing-raw-response-data-eg-headers

src/openlayer/resources/projects/projects.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def inference_pipelines(self) -> InferencePipelinesResource:
5656
@cached_property
5757
def with_raw_response(self) -> ProjectsResourceWithRawResponse:
5858
"""
59-
This property can be used as a prefix for any HTTP method call to return the
59+
This property can be used as a prefix for any HTTP method call to return
6060
the raw response object instead of the parsed content.
6161
6262
For more information, see https://www.github.com/openlayer-ai/openlayer-python#accessing-raw-response-data-eg-headers
@@ -187,7 +187,7 @@ def inference_pipelines(self) -> AsyncInferencePipelinesResource:
187187
@cached_property
188188
def with_raw_response(self) -> AsyncProjectsResourceWithRawResponse:
189189
"""
190-
This property can be used as a prefix for any HTTP method call to return the
190+
This property can be used as a prefix for any HTTP method call to return
191191
the raw response object instead of the parsed content.
192192
193193
For more information, see https://www.github.com/openlayer-ai/openlayer-python#accessing-raw-response-data-eg-headers

src/openlayer/resources/storage/presigned_url.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class PresignedURLResource(SyncAPIResource):
2828
@cached_property
2929
def with_raw_response(self) -> PresignedURLResourceWithRawResponse:
3030
"""
31-
This property can be used as a prefix for any HTTP method call to return the
31+
This property can be used as a prefix for any HTTP method call to return
3232
the raw response object instead of the parsed content.
3333
3434
For more information, see https://www.github.com/openlayer-ai/openlayer-python#accessing-raw-response-data-eg-headers
@@ -88,7 +88,7 @@ class AsyncPresignedURLResource(AsyncAPIResource):
8888
@cached_property
8989
def with_raw_response(self) -> AsyncPresignedURLResourceWithRawResponse:
9090
"""
91-
This property can be used as a prefix for any HTTP method call to return the
91+
This property can be used as a prefix for any HTTP method call to return
9292
the raw response object instead of the parsed content.
9393
9494
For more information, see https://www.github.com/openlayer-ai/openlayer-python#accessing-raw-response-data-eg-headers

0 commit comments

Comments
 (0)