Repository navigation
Commit 1743e65
committed
fix(signatures): raise clear error for field names that shadow SignatureMeta properties
Declaring a Signature field whose name collides with a SignatureMeta
property (e.g. `instructions`, which is a class-level property on the
metaclass for reading/writing the docstring) crashed signature class
construction with an opaque internal error:
class MySig(dspy.Signature):
instructions: str = dspy.InputField()
answer: str = dspy.OutputField()
# TypeError: 'NoneType' object is not subscriptable
Pydantic detects the name collision (it emits its own "shadows an
attribute in parent" UserWarning) and, for that field only, produces a
plain FieldInfo with json_schema_extra=None instead of preserving the
InputField()/OutputField() instance from the class body. SignatureMeta
already has validation for exactly this shape of problem -
_validate_fields() raises a clear TypeError when a field's
json_schema_extra doesn't carry the expected __dspy_field_type key -
but it ran too late: SignatureMeta.__new__ computes default
instructions first when no docstring is given, via
_default_instructions(cls) -> cls.input_fields ->
_get_fields_with_type(), which indexes json_schema_extra directly and
crashes before _validate_fields() ever gets a chance to run.
Move the existing _validate_fields() call to run immediately after
Pydantic builds the class, before anything reads json_schema_extra.
No new validation logic - just correct ordering of what was already
there.
Fixes #1710.1 parent 822f393 commit 1743e65
2 files changed
Lines changed: 23 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
184 | 184 | | |
185 | 185 | | |
186 | 186 | | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
187 | 195 | | |
188 | 196 | | |
189 | 197 | | |
| |||
198 | 206 | | |
199 | 207 | | |
200 | 208 | | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | 209 | | |
205 | 210 | | |
206 | 211 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
44 | 59 | | |
45 | 60 | | |
46 | 61 | | |
| |||
0 commit comments