Skip to content

fix(dspy): parse negative numbers in string signature Literal types - #10678

Merged
isaacbmiller merged 1 commit into
stanfordnlp:mainfrom
Blacksujit:fix/signature-negative-literal
Oct 27, 2026
Merged

isaacbmiller merged 1 commit into
stanfordnlp:mainfrom
Blacksujit:fix/signature-negative-literal

Conversation

@Blacksujit

@Blacksujit Blacksujit commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor
  • What breaks: dspy.Signature("q -> label: Literal[-1, 0, 1]") raises ValueError ("unhandled AST node type … UnaryOp").
  • But the class-based signature with Literal[-1, 0, 1] works fine.
  • Cause: the string-signature parser doesn't handle -/+ in front of a number.
  • Fix: evaluate unary -/+ on constants with ast.literal_eval (8 lines in dspy/signatures/signature.py).

tests/signatures: 114 passed, 2 xfailed
new test test_typed_signatures_literal_with_negative_numbers: fails on main, passes with fix

AI disclosure

  • Tool: Claude Code (Claude Opus).
  • How I used it: I asked it to sweep DSPy for user-facing bugs and draft a minimal fix with a regression test. I reviewed the diff and can explain every line.
  • Origin: sweep for issues (not encountered in normal usage).
  • Prompt (summary): "Find real bugs in DSPy where documented behaviour fails, confirm each on main, check for duplicates, and fix each with a test that fails before and passes after."
  • Verification: I reproduced the ValueError on main with dspy.Signature("q -> label: Literal[-1, 0, 1]") and ran pytest tests/signatures (114 passed, 2 xfailed).

@greptile-apps

greptile-apps Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] Safe to merge within the reviewed scope; no actionable findings remain.

Summary

Fixes string signatures containing signed numbers in Literal annotations by evaluating unary + and - only when their operand is a constant.

  • String signatures now accept signed numbers in Literal types.

No actionable issues found. Safe to merge within the reviewed scope.

Reviews (1) · Last reviewed commit: "fix(dspy): parse negative numbers in str..." · Reviewed by Greptile

@isaacbmiller isaacbmiller left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM - thanks for the PR!

@isaacbmiller
isaacbmiller merged commit cb2ed98 into stanfordnlp:main Oct 27, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants