Skip to content

Commit

Permalink
chore(internal): bump ruff version (#1604)
Browse files Browse the repository at this point in the history
  • Loading branch information
Stainless Bot committed Aug 6, 2024
1 parent a5f5c8e commit 3e19a87
Show file tree
Hide file tree
Showing 16 changed files with 76 additions and 142 deletions.
12 changes: 7 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ format = { chain = [
"check:ruff",
"typecheck",
]}
"check:ruff" = "ruff ."
"fix:ruff" = "ruff --fix ."
"check:ruff" = "ruff check ."
"fix:ruff" = "ruff check --fix ."

typecheck = { chain = [
"typecheck:pyright",
Expand Down Expand Up @@ -168,6 +168,11 @@ reportPrivateUsage = false
line-length = 120
output-format = "grouped"
target-version = "py37"

[tool.ruff.format]
docstring-code-format = true

[tool.ruff.lint]
select = [
# isort
"I",
Expand Down Expand Up @@ -198,9 +203,6 @@ unfixable = [
]
ignore-init-module-imports = true

[tool.ruff.format]
docstring-code-format = true

[tool.ruff.lint.flake8-tidy-imports.banned-api]
"functools.lru_cache".msg = "This function does not retain type information for the wrapped function's arguments; The `lru_cache` function from `_utils` should be used instead"

Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.lock
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ requests==2.31.0
respx==0.20.2
rich==13.7.1
# via inline-snapshot
ruff==0.1.9
ruff==0.5.6
setuptools==68.2.2
# via nodeenv
six==1.16.0
Expand Down
63 changes: 21 additions & 42 deletions src/openai/_base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,14 @@ def __init__(
self,
*,
url: URL,
) -> None:
...
) -> None: ...

@overload
def __init__(
self,
*,
params: Query,
) -> None:
...
) -> None: ...

def __init__(
self,
Expand Down Expand Up @@ -167,8 +165,7 @@ def has_next_page(self) -> bool:
return False
return self.next_page_info() is not None

def next_page_info(self) -> Optional[PageInfo]:
...
def next_page_info(self) -> Optional[PageInfo]: ...

def _get_page_items(self) -> Iterable[_T]: # type: ignore[empty-body]
...
Expand Down Expand Up @@ -904,8 +901,7 @@ def request(
*,
stream: Literal[True],
stream_cls: Type[_StreamT],
) -> _StreamT:
...
) -> _StreamT: ...

@overload
def request(
Expand All @@ -915,8 +911,7 @@ def request(
remaining_retries: Optional[int] = None,
*,
stream: Literal[False] = False,
) -> ResponseT:
...
) -> ResponseT: ...

@overload
def request(
Expand All @@ -927,8 +922,7 @@ def request(
*,
stream: bool = False,
stream_cls: Type[_StreamT] | None = None,
) -> ResponseT | _StreamT:
...
) -> ResponseT | _StreamT: ...

def request(
self,
Expand Down Expand Up @@ -1172,8 +1166,7 @@ def get(
cast_to: Type[ResponseT],
options: RequestOptions = {},
stream: Literal[False] = False,
) -> ResponseT:
...
) -> ResponseT: ...

@overload
def get(
Expand All @@ -1184,8 +1177,7 @@ def get(
options: RequestOptions = {},
stream: Literal[True],
stream_cls: type[_StreamT],
) -> _StreamT:
...
) -> _StreamT: ...

@overload
def get(
Expand All @@ -1196,8 +1188,7 @@ def get(
options: RequestOptions = {},
stream: bool,
stream_cls: type[_StreamT] | None = None,
) -> ResponseT | _StreamT:
...
) -> ResponseT | _StreamT: ...

def get(
self,
Expand All @@ -1223,8 +1214,7 @@ def post(
options: RequestOptions = {},
files: RequestFiles | None = None,
stream: Literal[False] = False,
) -> ResponseT:
...
) -> ResponseT: ...

@overload
def post(
Expand All @@ -1237,8 +1227,7 @@ def post(
files: RequestFiles | None = None,
stream: Literal[True],
stream_cls: type[_StreamT],
) -> _StreamT:
...
) -> _StreamT: ...

@overload
def post(
Expand All @@ -1251,8 +1240,7 @@ def post(
files: RequestFiles | None = None,
stream: bool,
stream_cls: type[_StreamT] | None = None,
) -> ResponseT | _StreamT:
...
) -> ResponseT | _StreamT: ...

def post(
self,
Expand Down Expand Up @@ -1485,8 +1473,7 @@ async def request(
*,
stream: Literal[False] = False,
remaining_retries: Optional[int] = None,
) -> ResponseT:
...
) -> ResponseT: ...

@overload
async def request(
Expand All @@ -1497,8 +1484,7 @@ async def request(
stream: Literal[True],
stream_cls: type[_AsyncStreamT],
remaining_retries: Optional[int] = None,
) -> _AsyncStreamT:
...
) -> _AsyncStreamT: ...

@overload
async def request(
Expand All @@ -1509,8 +1495,7 @@ async def request(
stream: bool,
stream_cls: type[_AsyncStreamT] | None = None,
remaining_retries: Optional[int] = None,
) -> ResponseT | _AsyncStreamT:
...
) -> ResponseT | _AsyncStreamT: ...

async def request(
self,
Expand Down Expand Up @@ -1739,8 +1724,7 @@ async def get(
cast_to: Type[ResponseT],
options: RequestOptions = {},
stream: Literal[False] = False,
) -> ResponseT:
...
) -> ResponseT: ...

@overload
async def get(
Expand All @@ -1751,8 +1735,7 @@ async def get(
options: RequestOptions = {},
stream: Literal[True],
stream_cls: type[_AsyncStreamT],
) -> _AsyncStreamT:
...
) -> _AsyncStreamT: ...

@overload
async def get(
Expand All @@ -1763,8 +1746,7 @@ async def get(
options: RequestOptions = {},
stream: bool,
stream_cls: type[_AsyncStreamT] | None = None,
) -> ResponseT | _AsyncStreamT:
...
) -> ResponseT | _AsyncStreamT: ...

async def get(
self,
Expand All @@ -1788,8 +1770,7 @@ async def post(
files: RequestFiles | None = None,
options: RequestOptions = {},
stream: Literal[False] = False,
) -> ResponseT:
...
) -> ResponseT: ...

@overload
async def post(
Expand All @@ -1802,8 +1783,7 @@ async def post(
options: RequestOptions = {},
stream: Literal[True],
stream_cls: type[_AsyncStreamT],
) -> _AsyncStreamT:
...
) -> _AsyncStreamT: ...

@overload
async def post(
Expand All @@ -1816,8 +1796,7 @@ async def post(
options: RequestOptions = {},
stream: bool,
stream_cls: type[_AsyncStreamT] | None = None,
) -> ResponseT | _AsyncStreamT:
...
) -> ResponseT | _AsyncStreamT: ...

async def post(
self,
Expand Down
24 changes: 8 additions & 16 deletions src/openai/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,22 +159,19 @@ def model_parse(model: type[_ModelT], data: Any) -> _ModelT:
# generic models
if TYPE_CHECKING:

class GenericModel(pydantic.BaseModel):
...
class GenericModel(pydantic.BaseModel): ...

else:
if PYDANTIC_V2:
# there no longer needs to be a distinction in v2 but
# we still have to create our own subclass to avoid
# inconsistent MRO ordering errors
class GenericModel(pydantic.BaseModel):
...
class GenericModel(pydantic.BaseModel): ...

else:
import pydantic.generics

class GenericModel(pydantic.generics.GenericModel, pydantic.BaseModel):
...
class GenericModel(pydantic.generics.GenericModel, pydantic.BaseModel): ...


# cached properties
Expand All @@ -193,26 +190,21 @@ class typed_cached_property(Generic[_T]):
func: Callable[[Any], _T]
attrname: str | None

def __init__(self, func: Callable[[Any], _T]) -> None:
...
def __init__(self, func: Callable[[Any], _T]) -> None: ...

@overload
def __get__(self, instance: None, owner: type[Any] | None = None) -> Self:
...
def __get__(self, instance: None, owner: type[Any] | None = None) -> Self: ...

@overload
def __get__(self, instance: object, owner: type[Any] | None = None) -> _T:
...
def __get__(self, instance: object, owner: type[Any] | None = None) -> _T: ...

def __get__(self, instance: object, owner: type[Any] | None = None) -> _T | Self:
raise NotImplementedError()

def __set_name__(self, owner: type[Any], name: str) -> None:
...
def __set_name__(self, owner: type[Any], name: str) -> None: ...

# __set__ is not defined at runtime, but @cached_property is designed to be settable
def __set__(self, instance: object, value: _T) -> None:
...
def __set__(self, instance: object, value: _T) -> None: ...
else:
try:
from functools import cached_property as cached_property
Expand Down
12 changes: 4 additions & 8 deletions src/openai/_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,11 @@ def assert_is_file_content(obj: object, *, key: str | None = None) -> None:


@overload
def to_httpx_files(files: None) -> None:
...
def to_httpx_files(files: None) -> None: ...


@overload
def to_httpx_files(files: RequestFiles) -> HttpxRequestFiles:
...
def to_httpx_files(files: RequestFiles) -> HttpxRequestFiles: ...


def to_httpx_files(files: RequestFiles | None) -> HttpxRequestFiles | None:
Expand Down Expand Up @@ -83,13 +81,11 @@ def _read_file_content(file: FileContent) -> HttpxFileContent:


@overload
async def async_to_httpx_files(files: None) -> None:
...
async def async_to_httpx_files(files: None) -> None: ...


@overload
async def async_to_httpx_files(files: RequestFiles) -> HttpxRequestFiles:
...
async def async_to_httpx_files(files: RequestFiles) -> HttpxRequestFiles: ...


async def async_to_httpx_files(files: RequestFiles | None) -> HttpxRequestFiles | None:
Expand Down
6 changes: 2 additions & 4 deletions src/openai/_legacy_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,10 @@ def request_id(self) -> str | None:
return self.http_response.headers.get("x-request-id") # type: ignore[no-any-return]

@overload
def parse(self, *, to: type[_T]) -> _T:
...
def parse(self, *, to: type[_T]) -> _T: ...

@overload
def parse(self) -> R:
...
def parse(self) -> R: ...

def parse(self, *, to: type[_T] | None = None) -> R | _T:
"""Returns the rich python representation of this response's data.
Expand Down
12 changes: 4 additions & 8 deletions src/openai/_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,10 @@ def request_id(self) -> str | None:
return self.http_response.headers.get("x-request-id") # type: ignore[no-any-return]

@overload
def parse(self, *, to: type[_T]) -> _T:
...
def parse(self, *, to: type[_T]) -> _T: ...

@overload
def parse(self) -> R:
...
def parse(self) -> R: ...

def parse(self, *, to: type[_T] | None = None) -> R | _T:
"""Returns the rich python representation of this response's data.
Expand Down Expand Up @@ -376,12 +374,10 @@ def request_id(self) -> str | None:
return self.http_response.headers.get("x-request-id") # type: ignore[no-any-return]

@overload
async def parse(self, *, to: type[_T]) -> _T:
...
async def parse(self, *, to: type[_T]) -> _T: ...

@overload
async def parse(self) -> R:
...
async def parse(self) -> R: ...

async def parse(self, *, to: type[_T] | None = None) -> R | _T:
"""Returns the rich python representation of this response's data.
Expand Down
Loading

0 comments on commit 3e19a87

Please sign in to comment.