Skip to content

Commit

Permalink
fix: Resolve create_model() TypeError in Partial class (#801)
Browse files Browse the repository at this point in the history
  • Loading branch information
slavakurilyak authored Jul 6, 2024
1 parent ba66784 commit a3cc27d
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions instructor/dsl/partial.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,14 @@ def get_partial_model(cls) -> type[T_Model]:
cls, BaseModel
), f"{cls.__name__} must be a subclass of BaseModel"

model_name = (
cls.__name__
if cls.__name__.startswith("Partial")
else f"Partial{cls.__name__}"
)

return create_model(
__model_name=(
cls.__name__
if cls.__name__.startswith("Partial")
else f"Partial{cls.__name__}"
),
model_name,
__base__=cls,
__module__=cls.__module__,
**{

Check failure on line 96 in instructor/dsl/partial.py

View workflow job for this annotation

GitHub Actions / Pyright (macos-latest, 3.11)

Argument of type "tuple[Any, FieldInfo]" cannot be assigned to parameter "__config__" of type "ConfigDict | None" in function "create_model"   Type "tuple[Any, FieldInfo]" is incompatible with type "ConfigDict | None"     "tuple[Any, FieldInfo]" is incompatible with "ConfigDict"     "tuple[Any, FieldInfo]" is incompatible with "None" (reportArgumentType)

Check failure on line 96 in instructor/dsl/partial.py

View workflow job for this annotation

GitHub Actions / Pyright (macos-latest, 3.11)

Argument of type "tuple[Any, FieldInfo]" cannot be assigned to parameter "__doc__" of type "str | None" in function "create_model"   Type "tuple[Any, FieldInfo]" is incompatible with type "str | None"     "tuple[Any, FieldInfo]" is incompatible with "str"     "tuple[Any, FieldInfo]" is incompatible with "None" (reportArgumentType)

Check failure on line 96 in instructor/dsl/partial.py

View workflow job for this annotation

GitHub Actions / Pyright (macos-latest, 3.11)

Argument of type "tuple[Any, FieldInfo]" cannot be assigned to parameter "__validators__" of type "dict[str, classmethod[Unknown, ..., Unknown]] | None" in function "create_model"   Type "tuple[Any, FieldInfo]" is incompatible with type "dict[str, classmethod[Unknown, ..., Unknown]] | None"     "tuple[Any, FieldInfo]" is incompatible with "dict[str, classmethod[Unknown, ..., Unknown]]"     "tuple[Any, FieldInfo]" is incompatible with "None" (reportArgumentType)

Check failure on line 96 in instructor/dsl/partial.py

View workflow job for this annotation

GitHub Actions / Pyright (macos-latest, 3.11)

Argument of type "tuple[Any, FieldInfo]" cannot be assigned to parameter "__cls_kwargs__" of type "dict[str, Any] | None" in function "create_model"   Type "tuple[Any, FieldInfo]" is incompatible with type "dict[str, Any] | None"     "tuple[Any, FieldInfo]" is incompatible with "dict[str, Any]"     "tuple[Any, FieldInfo]" is incompatible with "None" (reportArgumentType)
Expand Down Expand Up @@ -289,12 +291,14 @@ def _wrap_models(field: FieldInfo) -> tuple[object, FieldInfo]:
tmp_field.annotation = Partial[annotation]
return tmp_field.annotation, tmp_field

model_name = (
wrapped_class.__name__
if wrapped_class.__name__.startswith("Partial")
else f"Partial{wrapped_class.__name__}"
)

return create_model(
__model_name=(
wrapped_class.__name__
if wrapped_class.__name__.startswith("Partial")
else f"Partial{wrapped_class.__name__}"
),
model_name,
__base__=(wrapped_class, PartialBase),

Check failure on line 302 in instructor/dsl/partial.py

View workflow job for this annotation

GitHub Actions / Pyright (macos-latest, 3.11)

Argument of type "tuple[type[T_Model@Partial] | type[BaseModel]*, type[PartialBase[T_Model@PartialBase]]]" cannot be assigned to parameter "__base__" of type "type[Model@create_model] | tuple[type[Model@create_model], ...]" in function "create_model"   Type "tuple[type[T_Model@Partial] | type[BaseModel]*, type[PartialBase[T_Model@PartialBase]]]" is incompatible with type "type[Model@create_model] | tuple[type[Model@create_model], ...]"     Type "tuple[type[T_Model@Partial] | type[BaseModel]*, type[PartialBase[T_Model@PartialBase]]]" is incompatible with type "type[Model@create_model]"     "tuple[type[T_Model@Partial] | type[BaseModel]*, type[PartialBase[T_Model@PartialBase]]]" is incompatible with "tuple[type[Model@create_model], ...]"       Tuple entry 1 is incorrect type         Type "T_Model@Partial | BaseModel* | PartialBase[T_Model@PartialBase]" is incompatible with type "BaseModel*"           Type "BaseModel* | PartialBase[T_Model@PartialBase]" is incompatible with type "BaseModel*" (reportArgumentType)
__module__=wrapped_class.__module__,
**{

Check failure on line 304 in instructor/dsl/partial.py

View workflow job for this annotation

GitHub Actions / Pyright (macos-latest, 3.11)

Argument of type "tuple[Any, FieldInfo] | tuple[object, FieldInfo]" cannot be assigned to parameter "__config__" of type "ConfigDict | None" in function "create_model" (reportArgumentType)

Check failure on line 304 in instructor/dsl/partial.py

View workflow job for this annotation

GitHub Actions / Pyright (macos-latest, 3.11)

Argument of type "tuple[Any, FieldInfo] | tuple[object, FieldInfo]" cannot be assigned to parameter "__doc__" of type "str | None" in function "create_model" (reportArgumentType)

Check failure on line 304 in instructor/dsl/partial.py

View workflow job for this annotation

GitHub Actions / Pyright (macos-latest, 3.11)

Argument of type "tuple[Any, FieldInfo] | tuple[object, FieldInfo]" cannot be assigned to parameter "__validators__" of type "dict[str, classmethod[Unknown, ..., Unknown]] | None" in function "create_model" (reportArgumentType)

Check failure on line 304 in instructor/dsl/partial.py

View workflow job for this annotation

GitHub Actions / Pyright (macos-latest, 3.11)

Argument of type "tuple[Any, FieldInfo] | tuple[object, FieldInfo]" cannot be assigned to parameter "__cls_kwargs__" of type "dict[str, Any] | None" in function "create_model" (reportArgumentType)
Expand Down

0 comments on commit a3cc27d

Please sign in to comment.