Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0e67a8a

Browse files
Stainless BotRobertCraigie
Stainless Bot
authored andcommittedOct 28, 2024·
chore(internal): bump pytest to v8 & pydantic (#1829)
1 parent e1b2f82 commit 0e67a8a

File tree

8 files changed

+60
-53
lines changed

8 files changed

+60
-53
lines changed
 

‎requirements-dev.lock

+21-22
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,13 @@ argcomplete==3.1.2
1818
# via nox
1919
asttokens==2.4.1
2020
# via inline-snapshot
21-
attrs==23.1.0
21+
attrs==24.2.0
2222
# via outcome
23-
# via pytest
2423
# via trio
25-
azure-core==1.30.1
24+
azure-core==1.31.0
2625
# via azure-identity
27-
azure-identity==1.15.0
28-
black==24.4.2
26+
azure-identity==1.19.0
27+
black==24.10.0
2928
# via inline-snapshot
3029
certifi==2023.7.22
3130
# via httpcore
@@ -49,10 +48,11 @@ distlib==0.3.7
4948
# via virtualenv
5049
distro==1.8.0
5150
# via openai
52-
exceptiongroup==1.1.3
51+
exceptiongroup==1.2.2
5352
# via anyio
53+
# via pytest
5454
# via trio
55-
executing==2.0.1
55+
executing==2.1.0
5656
# via inline-snapshot
5757
filelock==3.12.4
5858
# via virtualenv
@@ -78,7 +78,7 @@ markdown-it-py==3.0.0
7878
# via rich
7979
mdurl==0.1.2
8080
# via markdown-it-py
81-
msal==1.29.0
81+
msal==1.31.0
8282
# via azure-identity
8383
# via msal-extensions
8484
msal-extensions==1.2.0
@@ -109,26 +109,24 @@ pathspec==0.12.1
109109
platformdirs==3.11.0
110110
# via black
111111
# via virtualenv
112-
pluggy==1.3.0
112+
pluggy==1.5.0
113113
# via pytest
114-
portalocker==2.8.2
114+
portalocker==2.10.1
115115
# via msal-extensions
116-
py==1.11.0
117-
# via pytest
118116
pycparser==2.22
119117
# via cffi
120-
pydantic==2.7.1
118+
pydantic==2.9.2
121119
# via openai
122-
pydantic-core==2.18.2
120+
pydantic-core==2.23.4
123121
# via pydantic
124122
pygments==2.18.0
125123
# via rich
126124
pyjwt==2.8.0
127125
# via msal
128126
pyright==1.1.380
129-
pytest==7.1.1
127+
pytest==8.3.3
130128
# via pytest-asyncio
131-
pytest-asyncio==0.21.1
129+
pytest-asyncio==0.24.0
132130
python-dateutil==2.8.2
133131
# via pandas
134132
# via time-machine
@@ -158,21 +156,22 @@ sortedcontainers==2.4.0
158156
time-machine==2.9.0
159157
toml==0.10.2
160158
# via inline-snapshot
161-
tomli==2.0.1
159+
tomli==2.0.2
162160
# via black
163161
# via mypy
164162
# via pytest
165-
tqdm==4.66.1
163+
tqdm==4.66.5
166164
# via openai
167-
trio==0.22.2
168-
types-pyaudio==0.2.16.20240106
169-
types-pytz==2024.1.0.20240417
165+
trio==0.27.0
166+
types-pyaudio==0.2.16.20240516
167+
types-pytz==2024.2.0.20241003
170168
# via pandas-stubs
171169
types-toml==0.10.8.20240310
172170
# via inline-snapshot
173-
types-tqdm==4.66.0.2
171+
types-tqdm==4.66.0.20240417
174172
typing-extensions==4.12.2
175173
# via azure-core
174+
# via azure-identity
176175
# via black
177176
# via mypy
178177
# via openai

‎requirements.lock

+9-9
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ certifi==2023.7.22
1919
# via httpx
2020
distro==1.8.0
2121
# via openai
22-
exceptiongroup==1.1.3
22+
exceptiongroup==1.2.2
2323
# via anyio
2424
h11==0.14.0
2525
# via httpcore
@@ -30,19 +30,19 @@ httpx==0.25.2
3030
idna==3.4
3131
# via anyio
3232
# via httpx
33-
jiter==0.5.0
33+
jiter==0.6.1
3434
# via openai
35-
numpy==1.26.4
35+
numpy==2.0.2
3636
# via openai
3737
# via pandas
3838
# via pandas-stubs
39-
pandas==2.2.2
39+
pandas==2.2.3
4040
# via openai
41-
pandas-stubs==2.2.1.240316
41+
pandas-stubs==2.2.2.240807
4242
# via openai
43-
pydantic==2.7.1
43+
pydantic==2.9.2
4444
# via openai
45-
pydantic-core==2.18.2
45+
pydantic-core==2.23.4
4646
# via pydantic
4747
python-dateutil==2.9.0.post0
4848
# via pandas
@@ -54,9 +54,9 @@ sniffio==1.3.0
5454
# via anyio
5555
# via httpx
5656
# via openai
57-
tqdm==4.66.1
57+
tqdm==4.66.5
5858
# via openai
59-
types-pytz==2024.1.0.20240417
59+
types-pytz==2024.2.0.20241003
6060
# via pandas-stubs
6161
typing-extensions==4.12.2
6262
# via openai

‎src/openai/_compat.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def model_json(model: pydantic.BaseModel, *, indent: int | None = None) -> str:
133133
def model_dump(
134134
model: pydantic.BaseModel,
135135
*,
136-
exclude: IncEx = None,
136+
exclude: IncEx | None = None,
137137
exclude_unset: bool = False,
138138
exclude_defaults: bool = False,
139139
warnings: bool = True,

‎src/openai/_models.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def __str__(self) -> str:
201201
# Based on https://github.com/samuelcolvin/pydantic/issues/1168#issuecomment-817742836.
202202
@classmethod
203203
@override
204-
def construct(
204+
def construct( # pyright: ignore[reportIncompatibleMethodOverride]
205205
cls: Type[ModelT],
206206
_fields_set: set[str] | None = None,
207207
**values: object,
@@ -273,8 +273,8 @@ def model_dump(
273273
self,
274274
*,
275275
mode: Literal["json", "python"] | str = "python",
276-
include: IncEx = None,
277-
exclude: IncEx = None,
276+
include: IncEx | None = None,
277+
exclude: IncEx | None = None,
278278
by_alias: bool = False,
279279
exclude_unset: bool = False,
280280
exclude_defaults: bool = False,
@@ -328,8 +328,8 @@ def model_dump_json(
328328
self,
329329
*,
330330
indent: int | None = None,
331-
include: IncEx = None,
332-
exclude: IncEx = None,
331+
include: IncEx | None = None,
332+
exclude: IncEx | None = None,
333333
by_alias: bool = False,
334334
exclude_unset: bool = False,
335335
exclude_defaults: bool = False,

‎src/openai/_types.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
Optional,
1717
Sequence,
1818
)
19-
from typing_extensions import Literal, Protocol, TypeAlias, TypedDict, override, runtime_checkable
19+
from typing_extensions import Set, Literal, Protocol, TypeAlias, TypedDict, override, runtime_checkable
2020

2121
import httpx
2222
import pydantic
@@ -195,7 +195,9 @@ def get(self, __key: str) -> str | None: ...
195195

196196
# Note: copied from Pydantic
197197
# https://github.com/pydantic/pydantic/blob/32ea570bf96e84234d2992e1ddf40ab8a565925a/pydantic/main.py#L49
198-
IncEx: TypeAlias = "set[int] | set[str] | dict[int, Any] | dict[str, Any] | None"
198+
IncEx: TypeAlias = Union[
199+
Set[int], Set[str], Mapping[int, Union["IncEx", Literal[True]]], Mapping[str, Union["IncEx", Literal[True]]]
200+
]
199201

200202
PostParser = Callable[[Any], Any]
201203

‎src/openai/lib/streaming/chat/_completions.py

+11-7
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
FunctionToolCallArgumentsDeltaEvent,
2424
)
2525
from .._deltas import accumulate_delta
26-
from ...._types import NOT_GIVEN, NotGiven
26+
from ...._types import NOT_GIVEN, IncEx, NotGiven
2727
from ...._utils import is_given, consume_sync_iterator, consume_async_iterator
2828
from ...._compat import model_dump
2929
from ...._models import build, construct_type
@@ -352,13 +352,17 @@ def _accumulate_chunk(self, chunk: ChatCompletionChunk) -> ParsedChatCompletionS
352352
# we don't want to serialise / deserialise our custom properties
353353
# as they won't appear in the delta and we don't want to have to
354354
# continuosly reparse the content
355-
exclude={
356-
"parsed": True,
357-
"tool_calls": {
358-
idx: {"function": {"parsed_arguments": True}}
359-
for idx, _ in enumerate(choice_snapshot.message.tool_calls or [])
355+
exclude=cast(
356+
# cast required as mypy isn't smart enough to infer `True` here to `Literal[True]`
357+
IncEx,
358+
{
359+
"parsed": True,
360+
"tool_calls": {
361+
idx: {"function": {"parsed_arguments": True}}
362+
for idx, _ in enumerate(choice_snapshot.message.tool_calls or [])
363+
},
360364
},
361-
},
365+
),
362366
),
363367
),
364368
cast("dict[object, object]", choice.delta.to_dict()),

‎tests/conftest.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
from __future__ import annotations
22

33
import os
4-
import asyncio
54
import logging
65
from typing import TYPE_CHECKING, Iterator, AsyncIterator
76

87
import pytest
8+
from pytest_asyncio import is_async_test
99

1010
from openai import OpenAI, AsyncOpenAI
1111

@@ -17,11 +17,13 @@
1717
logging.getLogger("openai").setLevel(logging.DEBUG)
1818

1919

20-
@pytest.fixture(scope="session")
21-
def event_loop() -> Iterator[asyncio.AbstractEventLoop]:
22-
loop = asyncio.new_event_loop()
23-
yield loop
24-
loop.close()
20+
# automatically add `pytest.mark.asyncio()` to all of our async tests
21+
# so we don't have to add that boilerplate everywhere
22+
def pytest_collection_modifyitems(items: list[pytest.Function]) -> None:
23+
pytest_asyncio_tests = (item for item in items if is_async_test(item))
24+
session_scope_marker = pytest.mark.asyncio(loop_scope="session")
25+
for async_test in pytest_asyncio_tests:
26+
async_test.add_marker(session_scope_marker, append=False)
2527

2628

2729
base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")

‎tests/lib/test_old_api.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
def test_basic_attribute_access_works() -> None:
88
for attr in dir(openai):
9-
dir(getattr(openai, attr))
9+
getattr(openai, attr)
1010

1111

1212
def test_helpful_error_is_raised() -> None:

0 commit comments

Comments
 (0)
Please sign in to comment.