Skip to content

Commit

Permalink
chore(client): improve copy method (#246)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-bot authored Nov 21, 2023
1 parent 9fc275f commit c84563f
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/anthropic/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

import os
import asyncio
from typing import Union, Mapping
from typing_extensions import override
from typing import Any, Union, Mapping
from typing_extensions import Self, override

import httpx
from tokenizers import Tokenizer # type: ignore[import]
Expand Down Expand Up @@ -194,12 +194,10 @@ def copy(
set_default_headers: Mapping[str, str] | None = None,
default_query: Mapping[str, object] | None = None,
set_default_query: Mapping[str, object] | None = None,
) -> Anthropic:
_extra_kwargs: Mapping[str, Any] = {},
) -> Self:
"""
Create a new client instance re-using the same options given to the current client with optional overriding.
It should be noted that this does not share the underlying httpx client class which may lead
to performance issues.
"""
if default_headers is not None and set_default_headers is not None:
raise ValueError("The `default_headers` and `set_default_headers` arguments are mutually exclusive")
Expand Down Expand Up @@ -247,6 +245,7 @@ def copy(
max_retries=max_retries if is_given(max_retries) else self.max_retries,
default_headers=headers,
default_query=params,
**_extra_kwargs,
)

# Alias for `copy` for nicer inline usage, e.g.
Expand Down Expand Up @@ -455,12 +454,10 @@ def copy(
set_default_headers: Mapping[str, str] | None = None,
default_query: Mapping[str, object] | None = None,
set_default_query: Mapping[str, object] | None = None,
) -> AsyncAnthropic:
_extra_kwargs: Mapping[str, Any] = {},
) -> Self:
"""
Create a new client instance re-using the same options given to the current client with optional overriding.
It should be noted that this does not share the underlying httpx client class which may lead
to performance issues.
"""
if default_headers is not None and set_default_headers is not None:
raise ValueError("The `default_headers` and `set_default_headers` arguments are mutually exclusive")
Expand Down Expand Up @@ -508,6 +505,7 @@ def copy(
max_retries=max_retries if is_given(max_retries) else self.max_retries,
default_headers=headers,
default_query=params,
**_extra_kwargs,
)

# Alias for `copy` for nicer inline usage, e.g.
Expand Down

0 comments on commit c84563f

Please sign in to comment.