Add type annotations to sympy.logic.inference - #30532
Open
MateoLauzardo wants to merge 1 commit into
Open
MateoLauzardo wants to merge 1 commit into
MateoLauzardo wants to merge 1 commit into
Conversation
Annotate valid, entails and pl_true. pl_true's body was rebinding its parameters to wider types, so intermediate values now use separate local names. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
✅ Hi, I am the SymPy bot. I'm here to help you write a release notes entry. Please read the guide on how to write release notes.
Click here to see the pull request description that was parsed. |
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 characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
References to other Issues or PRs
See #28806
Brief description of what is fixed or changed
Adds type annotations to
sympy/logic/inference.pyandrelease/authors.py.In
inference.pyI annotatedvalid,pl_true, its inner_validate, andentails, plus aModelalias for the assignment dictspl_truepassesaround; in
authors.py,blue,red, andget_authors. I leftliteral_symbolandsatisfiablealone —satisfiable's return type varieswith
all_modelsand the chosen algorithm, so it needs overloads rather thanone signature, which felt like its own change.
Other comments
pl_truereboundexprandmodelto different types inside the body, whichmypy rejects. Rather than widen the parameter types, I gave the intermediates
new names —
sexprfor the sympified expression,deep_modelfor the atomsdict — so the parameters keep the types in their signature. No behaviour
change, but it's the one spot where the diff is more than added annotations.
While typing the return I noticed
pl_trueisn't consistent about booleanresults: an input already in
(True, False)comes back as-is viareturn expr, while a result that reduces aftersubsgoes throughbool(result).Because
BooleanTruecompares equal toTrue,pl_true(true)returnsBooleanTruebutpl_true(x, {x: True})returns a Pythonbool. I typed thereturn as
Boolean | bool | Noneto cover both. Would you rather narrow it tobool | Noneand convert in the first branch, or is the current behaviourdepended on somewhere?
AI Generation Disclosure
Claude Code (Claude Opus 5), run in VSCode against a local clone.
sympy/logic/inference.py — AI-generated: the annotations on valid, entails,
pl_true and _validate; the Model alias and TYPE_CHECKING block; and the
pl_true body changes (sexpr, deep_model, and the cast on subs).
release/authors.py — AI-generated: the annotations on blue, red and
get_authors, and the added future import.
I reviewed every line. mypy sympy reports no errors across 1553 files,
ruff check sympy passes, sympy/logic/tests gives 136 passed, and
bin/doctest sympy/logic/inference.py and bin/test quality both pass.
Release Notes
NO ENTRY