Skip to content

Commit 0db14f1

Browse files
cpsievertCopilot
andauthored
fix: script for type generation now handles nexted module importing correctly when type doesn't have an origin (#152)
* fix: script for type generation now handles nexted module importing correctly when type doesn't have an origin * Apply suggestions from code review Co-authored-by: Copilot <[email protected]> * need to skip bedrock tests more generally * Update anthripic types * Manually fix? --------- Co-authored-by: Copilot <[email protected]>
1 parent d519031 commit 0db14f1

File tree

8 files changed

+28
-10
lines changed

8 files changed

+28
-10
lines changed

chatlas/types/anthropic/_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ class ChatClientArgs(TypedDict, total=False):
1717
max_retries: int
1818
default_headers: Optional[Mapping[str, str]]
1919
default_query: Optional[Mapping[str, object]]
20-
http_client: httpx.AsyncClient
20+
http_client: httpx.AsyncClient | None
2121
_strict_response_validation: bool

chatlas/types/anthropic/_client_bedrock.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ class ChatBedrockClientArgs(TypedDict, total=False):
1919
max_retries: int
2020
default_headers: Optional[Mapping[str, str]]
2121
default_query: Optional[Mapping[str, object]]
22-
http_client: httpx.AsyncClient
22+
http_client: httpx.AsyncClient | None
2323
_strict_response_validation: bool

chatlas/types/openai/_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ class ChatClientArgs(TypedDict, total=False):
2020
max_retries: int
2121
default_headers: Optional[Mapping[str, str]]
2222
default_query: Optional[Mapping[str, object]]
23-
http_client: httpx.AsyncClient
23+
http_client: httpx.AsyncClient | None
2424
_strict_response_validation: bool

chatlas/types/openai/_client_azure.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ class ChatAzureClientArgs(TypedDict, total=False):
2323
max_retries: int
2424
default_headers: Optional[Mapping[str, str]]
2525
default_query: Optional[Mapping[str, object]]
26-
http_client: httpx.AsyncClient
26+
http_client: httpx.AsyncClient | None
2727
_strict_response_validation: bool

chatlas/types/openai/_submit.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ class SubmitInputArgs(TypedDict, total=False):
177177
top_p: Union[float, None, openai.NotGiven]
178178
user: str | openai.NotGiven
179179
verbosity: Union[Literal["low", "medium", "high"], None, openai.NotGiven]
180+
web_search_options: (
181+
openai.types.chat.completion_create_params.WebSearchOptions | openai.NotGiven
182+
)
180183
extra_headers: Optional[Mapping[str, Union[str, openai.Omit]]]
181184
extra_query: Optional[Mapping[str, object]]
182185
extra_body: object | None

scripts/_generate_openai_types.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
create_args = generate_typeddict_code(
1515
Completions.create,
1616
"SubmitInputArgs",
17-
# For some reason web_search_options is not being generated correctly
18-
excluded_fields={"self", "web_search_options"},
17+
excluded_fields={"self"},
1918
)
2019

2120
write_code_to_file(

scripts/_utils.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,27 @@ def get_type_string(typ: Any) -> tuple[str, set[str]]:
142142
imports.add(f"from typing import {type_name}")
143143
return type_str.replace("typing.", ""), imports
144144

145+
# Handle namespaced types (including union syntax)
146+
if "|" in type_str:
147+
parts = [part.strip() for part in type_str.split("|")]
148+
processed_parts = []
149+
for part in parts:
150+
namespace_match = re.match(
151+
r"([a-zA-Z_][a-zA-Z0-9_.]*)\.([a-zA-Z_][a-zA-Z0-9_]*)",
152+
part,
153+
)
154+
if namespace_match:
155+
namespace, type_name = namespace_match.groups()
156+
imports.add(f"import {namespace}")
157+
processed_parts.append(f"{namespace}.{type_name}")
158+
else:
159+
processed_parts.append(part)
160+
return " | ".join(processed_parts), imports
161+
145162
# Handle namespaced types
146163
namespace_match = re.match(
147-
r"([a-zA-Z_][a-zA-Z0-9_]*)\.([a-zA-Z_][a-zA-Z0-9_]*)", type_str
164+
r"([a-zA-Z_][a-zA-Z0-9_.]*)\.([a-zA-Z_][a-zA-Z0-9_]*)",
165+
type_str,
148166
)
149167
if namespace_match:
150168
namespace, type_name = namespace_match.groups()

tests/test_provider_bedrock.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import pytest
2-
32
from chatlas import ChatBedrockAnthropic
4-
from botocore.exceptions import TokenRetrievalError
53

64
from .conftest import (
75
assert_data_extraction,
@@ -18,7 +16,7 @@
1816
try:
1917
chat = ChatBedrockAnthropic()
2018
chat.chat("What is 1 + 1?")
21-
except TokenRetrievalError:
19+
except Exception:
2220
pytest.skip("Bedrock credentials aren't configured", allow_module_level=True)
2321

2422

0 commit comments

Comments
 (0)