Skip to content

Commit

Permalink
chore(internal): bump pytest to v8 & pydantic (openai#1829)
Browse files Browse the repository at this point in the history
  • Loading branch information
Stainless Bot authored and stainless-app[bot] committed Oct 30, 2024
1 parent b3d8303 commit 9636536
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 53 deletions.
43 changes: 21 additions & 22 deletions requirements-dev.lock
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@ argcomplete==3.1.2
# via nox
asttokens==2.4.1
# via inline-snapshot
attrs==23.1.0
attrs==24.2.0
# via outcome
# via pytest
# via trio
azure-core==1.30.1
azure-core==1.31.0
# via azure-identity
azure-identity==1.15.0
black==24.4.2
azure-identity==1.19.0
black==24.10.0
# via inline-snapshot
certifi==2023.7.22
# via httpcore
Expand All @@ -49,10 +48,11 @@ distlib==0.3.7
# via virtualenv
distro==1.8.0
# via openai
exceptiongroup==1.1.3
exceptiongroup==1.2.2
# via anyio
# via pytest
# via trio
executing==2.0.1
executing==2.1.0
# via inline-snapshot
filelock==3.12.4
# via virtualenv
Expand All @@ -78,7 +78,7 @@ markdown-it-py==3.0.0
# via rich
mdurl==0.1.2
# via markdown-it-py
msal==1.29.0
msal==1.31.0
# via azure-identity
# via msal-extensions
msal-extensions==1.2.0
Expand Down Expand Up @@ -109,26 +109,24 @@ pathspec==0.12.1
platformdirs==3.11.0
# via black
# via virtualenv
pluggy==1.3.0
pluggy==1.5.0
# via pytest
portalocker==2.8.2
portalocker==2.10.1
# via msal-extensions
py==1.11.0
# via pytest
pycparser==2.22
# via cffi
pydantic==2.7.1
pydantic==2.9.2
# via openai
pydantic-core==2.18.2
pydantic-core==2.23.4
# via pydantic
pygments==2.18.0
# via rich
pyjwt==2.8.0
# via msal
pyright==1.1.380
pytest==7.1.1
pytest==8.3.3
# via pytest-asyncio
pytest-asyncio==0.21.1
pytest-asyncio==0.24.0
python-dateutil==2.8.2
# via pandas
# via time-machine
Expand Down Expand Up @@ -158,21 +156,22 @@ sortedcontainers==2.4.0
time-machine==2.9.0
toml==0.10.2
# via inline-snapshot
tomli==2.0.1
tomli==2.0.2
# via black
# via mypy
# via pytest
tqdm==4.66.1
tqdm==4.66.5
# via openai
trio==0.22.2
types-pyaudio==0.2.16.20240106
types-pytz==2024.1.0.20240417
trio==0.27.0
types-pyaudio==0.2.16.20240516
types-pytz==2024.2.0.20241003
# via pandas-stubs
types-toml==0.10.8.20240310
# via inline-snapshot
types-tqdm==4.66.0.2
types-tqdm==4.66.0.20240417
typing-extensions==4.12.2
# via azure-core
# via azure-identity
# via black
# via mypy
# via openai
Expand Down
18 changes: 9 additions & 9 deletions requirements.lock
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ certifi==2023.7.22
# via httpx
distro==1.8.0
# via openai
exceptiongroup==1.1.3
exceptiongroup==1.2.2
# via anyio
h11==0.14.0
# via httpcore
Expand All @@ -30,19 +30,19 @@ httpx==0.25.2
idna==3.4
# via anyio
# via httpx
jiter==0.5.0
jiter==0.6.1
# via openai
numpy==1.26.4
numpy==2.0.2
# via openai
# via pandas
# via pandas-stubs
pandas==2.2.2
pandas==2.2.3
# via openai
pandas-stubs==2.2.1.240316
pandas-stubs==2.2.2.240807
# via openai
pydantic==2.7.1
pydantic==2.9.2
# via openai
pydantic-core==2.18.2
pydantic-core==2.23.4
# via pydantic
python-dateutil==2.9.0.post0
# via pandas
Expand All @@ -54,9 +54,9 @@ sniffio==1.3.0
# via anyio
# via httpx
# via openai
tqdm==4.66.1
tqdm==4.66.5
# via openai
types-pytz==2024.1.0.20240417
types-pytz==2024.2.0.20241003
# via pandas-stubs
typing-extensions==4.12.2
# via openai
Expand Down
2 changes: 1 addition & 1 deletion src/openai/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def model_json(model: pydantic.BaseModel, *, indent: int | None = None) -> str:
def model_dump(
model: pydantic.BaseModel,
*,
exclude: IncEx = None,
exclude: IncEx | None = None,
exclude_unset: bool = False,
exclude_defaults: bool = False,
warnings: bool = True,
Expand Down
10 changes: 5 additions & 5 deletions src/openai/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def __str__(self) -> str:
# Based on https://github.com/samuelcolvin/pydantic/issues/1168#issuecomment-817742836.
@classmethod
@override
def construct(
def construct( # pyright: ignore[reportIncompatibleMethodOverride]
cls: Type[ModelT],
_fields_set: set[str] | None = None,
**values: object,
Expand Down Expand Up @@ -273,8 +273,8 @@ def model_dump(
self,
*,
mode: Literal["json", "python"] | str = "python",
include: IncEx = None,
exclude: IncEx = None,
include: IncEx | None = None,
exclude: IncEx | None = None,
by_alias: bool = False,
exclude_unset: bool = False,
exclude_defaults: bool = False,
Expand Down Expand Up @@ -328,8 +328,8 @@ def model_dump_json(
self,
*,
indent: int | None = None,
include: IncEx = None,
exclude: IncEx = None,
include: IncEx | None = None,
exclude: IncEx | None = None,
by_alias: bool = False,
exclude_unset: bool = False,
exclude_defaults: bool = False,
Expand Down
6 changes: 4 additions & 2 deletions src/openai/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
Optional,
Sequence,
)
from typing_extensions import Literal, Protocol, TypeAlias, TypedDict, override, runtime_checkable
from typing_extensions import Set, Literal, Protocol, TypeAlias, TypedDict, override, runtime_checkable

import httpx
import pydantic
Expand Down Expand Up @@ -195,7 +195,9 @@ def get(self, __key: str) -> str | None: ...

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

PostParser = Callable[[Any], Any]

Expand Down
18 changes: 11 additions & 7 deletions src/openai/lib/streaming/chat/_completions.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
FunctionToolCallArgumentsDeltaEvent,
)
from .._deltas import accumulate_delta
from ...._types import NOT_GIVEN, NotGiven
from ...._types import NOT_GIVEN, IncEx, NotGiven
from ...._utils import is_given, consume_sync_iterator, consume_async_iterator
from ...._compat import model_dump
from ...._models import build, construct_type
Expand Down Expand Up @@ -352,13 +352,17 @@ def _accumulate_chunk(self, chunk: ChatCompletionChunk) -> ParsedChatCompletionS
# we don't want to serialise / deserialise our custom properties
# as they won't appear in the delta and we don't want to have to
# continuosly reparse the content
exclude={
"parsed": True,
"tool_calls": {
idx: {"function": {"parsed_arguments": True}}
for idx, _ in enumerate(choice_snapshot.message.tool_calls or [])
exclude=cast(
# cast required as mypy isn't smart enough to infer `True` here to `Literal[True]`
IncEx,
{
"parsed": True,
"tool_calls": {
idx: {"function": {"parsed_arguments": True}}
for idx, _ in enumerate(choice_snapshot.message.tool_calls or [])
},
},
},
),
),
),
cast("dict[object, object]", choice.delta.to_dict()),
Expand Down
14 changes: 8 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from __future__ import annotations

import os
import asyncio
import logging
from typing import TYPE_CHECKING, Iterator, AsyncIterator

import pytest
from pytest_asyncio import is_async_test

from openai import OpenAI, AsyncOpenAI

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


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


base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/test_old_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

def test_basic_attribute_access_works() -> None:
for attr in dir(openai):
dir(getattr(openai, attr))
getattr(openai, attr)


def test_helpful_error_is_raised() -> None:
Expand Down

0 comments on commit 9636536

Please sign in to comment.