44
55import os
66import json
7- from typing import cast
7+ from typing import Any , cast
88
99import httpx
1010import pytest
11- from pydantic import BaseModel
1211from respx import MockRouter
12+ from pydantic import BaseModel
1313from respx .models import Call
1414
15- from stagehand import AsyncStagehand , Stagehand
15+ from stagehand import Stagehand , AsyncStagehand
1616
1717base_url = os .environ .get ("TEST_API_BASE_URL" , "http://127.0.0.1:4010" )
1818
@@ -45,7 +45,7 @@ def test_session_extract_accepts_pydantic_schema(respx_mock: MockRouter, client:
4545 )
4646
4747 session = client .sessions .start (model_name = "openai/gpt-5-nano" )
48- response = session .extract (instruction = "extract the user" , schema = ExtractedUser )
48+ response = session .extract (instruction = "extract the user" , schema = cast ( Any , ExtractedUser ) )
4949
5050 assert isinstance (response .data .result , ExtractedUser )
5151 assert response .data .result .user_name == "Ada"
@@ -79,7 +79,7 @@ def test_session_extract_allows_extra_fields_when_client_is_non_strict(
7979 )
8080
8181 session = client .sessions .start (model_name = "openai/gpt-5-nano" )
82- response = session .extract (instruction = "extract the user" , schema = ExtractedName )
82+ response = session .extract (instruction = "extract the user" , schema = cast ( Any , ExtractedName ) )
8383
8484 assert isinstance (response .data .result , ExtractedName )
8585 assert response .data .result .user_name == "Ada"
@@ -107,7 +107,7 @@ def test_session_extract_rejects_extra_fields_when_client_is_strict(
107107 )
108108
109109 session = client .sessions .start (model_name = "openai/gpt-5-nano" )
110- response = session .extract (instruction = "extract the user" , schema = ExtractedName )
110+ response = session .extract (instruction = "extract the user" , schema = cast ( Any , ExtractedName ) )
111111
112112 assert response .data .result == {"userName" : "Ada" , "favoriteColor" : "blue" }
113113
@@ -133,7 +133,7 @@ async def test_async_session_extract_accepts_pydantic_schema(
133133 )
134134
135135 session = await async_client .sessions .start (model_name = "openai/gpt-5-nano" )
136- response = await session .extract (instruction = "extract the user" , schema = ExtractedUser )
136+ response = await session .extract (instruction = "extract the user" , schema = cast ( Any , ExtractedUser ) )
137137
138138 assert isinstance (response .data .result , ExtractedUser )
139139 assert response .data .result .user_name == "Grace"
@@ -167,7 +167,7 @@ async def test_async_session_extract_allows_extra_fields_when_client_is_non_stri
167167 )
168168
169169 session = await async_client .sessions .start (model_name = "openai/gpt-5-nano" )
170- response = await session .extract (instruction = "extract the user" , schema = ExtractedName )
170+ response = await session .extract (instruction = "extract the user" , schema = cast ( Any , ExtractedName ) )
171171
172172 assert isinstance (response .data .result , ExtractedName )
173173 assert response .data .result .user_name == "Grace"
@@ -195,6 +195,6 @@ async def test_async_session_extract_rejects_extra_fields_when_client_is_strict(
195195 )
196196
197197 session = await async_client .sessions .start (model_name = "openai/gpt-5-nano" )
198- response = await session .extract (instruction = "extract the user" , schema = ExtractedName )
198+ response = await session .extract (instruction = "extract the user" , schema = cast ( Any , ExtractedName ) )
199199
200200 assert response .data .result == {"userName" : "Grace" , "favoriteColor" : "green" }
0 commit comments