Created
May 3, 2024 20:53
-
-
Save rpgoldman/44ab1c8352f0f8bf985d6ec29a83db20 to your computer and use it in GitHub Desktop.
Revisions
-
rpgoldman created this gist
May 3, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ dspy/signatures/mypy_issue.py:35: error: Too many arguments for "Signature" [call-arg] dspy/signatures/mypy_issue.py:35: error: Incompatible return value type (got "Signature", expected "type[Signature]") [return-value] Found 2 errors in 1 file (checked 1 source file) This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,40 @@ import typing from typing import Union, Type, Optional import pydantic.fields from pydantic import BaseModel, Field, create_model from pydantic.fields import FieldInfo import dsp from dspy.signatures.field import InputField, OutputField, new_to_old_field # I don't love this, but mypy cannot deal with the dynamic lookup of this metaclass - rpg PydanticMetaClass: typing.TypeAlias = pydantic._internal._model_construction.ModelMetaclass assert PydanticMetaClass == type(pydantic.BaseModel), \ "Implementation of Signature MetaClass depends on the internals of Pydantic, which have changed." class SignatureMeta(PydanticMetaClass): pass class Signature(BaseModel, metaclass=SignatureMeta): """""" # noqa: D419 pass # example usages def ensure_signature( signature: Union[str, Type[Signature]], instructions: Optional[str] = None ) -> Type[Signature]: if signature is None: raise ValueError("Signature argument is mandatory") if isinstance(signature, str): # FIXME: According to mypy, Signature cannot be called with 2 arguments. return Signature(signature, instructions) if instructions is not None: raise ValueError( "Don't specify instructions when initializing with a Signature" ) return signature