Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iterable Workaround #737

Merged
merged 10 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion instructor/dsl/simple_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,27 @@ def __class_getitem__(cls, response_model: type[BaseModel]) -> type[BaseModel]:
)


def validateIsSubClass(response_model: type):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

snake case

"""
Temporary guard against issues with generics in Python 3.9
"""
import sys

if sys.version_info < (3, 10):
if len(typing.get_args(response_model)) == 0:
return False
return issubclass(typing.get_args(response_model)[0], BaseModel)
return issubclass(response_model, BaseModel)


def is_simple_type(
response_model: type[BaseModel] | str | int | float | bool | typing.Any,
) -> bool:
# ! we're getting mixes between classes and instances due to how we handle some
# ! response model types, we should fix this in later PRs

try:
if isclass(response_model) and issubclass(response_model, BaseModel):
if isclass(response_model) and validateIsSubClass(response_model):
return False
except TypeError:
# ! In versions < 3.11, typing.Iterable is not a class, so we can't use isclass
Expand Down
Loading
Loading