Extract richer PySpec data: class hierarchy, kwargs, and assert preconditions#494
Open
joehendrix wants to merge 1 commit intomainfrom
Open
Extract richer PySpec data: class hierarchy, kwargs, and assert preconditions#494joehendrix wants to merge 1 commit intomainfrom
joehendrix wants to merge 1 commit intomainfrom
Conversation
f72b25b to
d1e291c
Compare
…nditions Extend the PySpec translator to handle richer Python constructs: class inheritance with inner classes (exception hierarchies), **kwargs parameter storage, and translation of assert statements into structured SpecExpr preconditions. Six new DDM categories and a specWarning method on PySpecMClass support round-trip serialization and non-fatal diagnostics. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
d1e291c to
f11ba72
Compare
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.
Summary
This PR extends the PySpec translator to handle richer Python constructs:
class inheritance with inner classes (exception hierarchies),
**kwargsparameter storage, and translation of
assertstatements into structuredSpecExprpreconditions. Six new DDM categories and aspecWarningmethod on
PySpecMClasssupport round-trip serialization and non-fataldiagnostics.
Details
ClassDefgainsbases,fields,classVars, andsubclassesfields. The translator now parses baseclass lists (resolving names to
PythonIdent, special-casingException), field declarations (AnnAssign), class variableassignments (
Assign), and innerClassDefstatements. A newClassDeclDDM category withClassFieldDeclandClassVarDeclsub-categories provides serialization.
FieldDeclis renamed toDictFieldDeclto disambiguate fromClassFieldDecl.**kwargsstored as a single typed parameter.ArgDeclsgains akwargs : Option (String × SpecType)field that preserves the parametername and its type, rather than expanding TypedDict fields into
individual kwonly args. A new
KwargsDeclDDM category encodes this asa 0-or-1-element
Seq, consistent with how DDM represents optionalityelsewhere.
SpecExprpreconditions. The oldSpecPredplaceholder is replaced by aSpecExprinductive withconstructors for six assert patterns:
isinstance,len >=/<=,value >=/<=, andenum ==chains.getIndextakes a recursiveSpecExprsubject with avarbase case, so nested subscripts likekwargs["ContactInformation"]["FullName"]can be represented whensupport is added later. Unrecognized patterns produce
.placeholderwith a
specWarningincluding the full AST.(
ClassFieldDecl,ClassVarDecl,ClassDecl,KwargsDecl,SpecExprDecl,Assertion) with symmetrictoDDM/fromDDMpairs.mkFunDeclnow serializeskwargs,preconditions, andpostconditions.FieldDeclrenamed toDictFieldDecl.specWarninginfrastructure.PySpecMClassgains aspecWarningmethod so the translator can report non-fatal issues (skipped
statements, unrecognized patterns) without aborting. Warnings are
emitted to stderr at the end of translation.
transAssertExprandcollectEnumValuesusesdecidePropordependent
if h :instead of forced[0]!/[1]!, letting the typechecker verify bounds statically.
kwargs_function(**kw: str)with
isinstanceandvalueGeasserts is added tomain.pywithcorresponding expected DDM output in
SpecsTest.lean.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.