Skip to content

chore: roll 1.59 - #3024

Closed
Simon Knott (Skn0tt) wants to merge 1 commit into
microsoft:mainfrom
Skn0tt:roll-1-58
Closed

chore: roll 1.59#3024
Simon Knott (Skn0tt) wants to merge 1 commit into
microsoft:mainfrom
Skn0tt:roll-1-58

Conversation

@Skn0tt

Copy link
Copy Markdown
Member

No description provided.

@Skn0tt

Simon Knott (Skn0tt) commented Jan 20, 2026

Copy link
Copy Markdown
Member Author
from typing import Any, TypeVar, overload, Callable

T = TypeVar("T")
type JsonSchema = dict[str, Any]


@overload
def extract(schema: Callable[..., T], text: str) -> T: ...
@overload
def extract(schema: JsonSchema, text: str) -> Any: ...
def extract(schema: Callable[..., T] | JsonSchema, text: str) -> T | Any:
    raise NotImplementedError()


# --- Demo ---

from pydantic import BaseModel


class User(BaseModel):
    id: int
    name: str


# Pydantic model → typed result
user = extract(User, "My name is Alice and my id is 1")
user.name  # ✅ IDE knows this is `str`

# JSON schema → Any
data = extract({"type": "object"}, "some text")
data["foo"]  # ⚠️ IDE sees this as `Any`

@Skn0tt Simon Knott (Skn0tt) changed the title chore: roll 1.58 chore: roll 1.59 Jan 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant