DSPy: The framework for programming—not prompting—language models
Python
fix(dspy): Remove common indentations in signature according to Python docstring standards
wulllif5e39eef9581
diff --git a/dspy/signatures/signature.py b/dspy/signatures/signature.pyindex d10f71718..3ad35c31b 100644--- a/dspy/signatures/signature.py+++ b/dspy/signatures/signature.py@@ -1,4 +1,5 @@import ast+import inspectimport reimport typesimport typing@@ -88,7 +89,7 @@ class SignatureMeta(type(BaseModel)):@propertydef instructions(cls) -> str:- return getattr(cls, "__doc__", "")+ return inspect.cleandoc(getattr(cls, "__doc__", ""))def with_instructions(cls, instructions: str) -> Type["Signature"]:return Signature(cls.fields, instructions)@@ -217,9 +218,9 @@ def ensure_signature(signature: Union[str, Type[Signature]], instructions=None)def make_signature(- signature: Union[str, Dict[str, Tuple[type, FieldInfo]]],- instructions: str = None,- signature_name: str = "StringSignature",+ signature: Union[str, Dict[str, Tuple[type, FieldInfo]]],+ instructions: str = None,+ signature_name: str = "StringSignature",) -> Type[Signature]:"""Create a new Signature type with the given fields and instructions.diff --git a/tests/signatures/test_signature.py b/tests/signatures/test_signature.pyindex d0eb899d1..e635455b9 100644--- a/tests/signatures/test_signature.py+++ b/tests/signatures/test_signature.py@@ -183,7 +183,8 @@ def test_insantiating2():def test_multiline_instructions():class MySignature(Signature):"""First line- Second line"""+ Second line+ Third line"""output = OutputField()@@ -195,7 +196,8 @@ def test_multiline_instructions():assert lm.get_convo(-1) == textwrap.dedent("""\First line- Second line+ Second line+ Third line---