Skip to content

refactor: remove dead DeclaredContract/TypeConstraint infrastructure#14

Merged
tob-scott-a merged 1 commit into
mainfrom
declared-contract-decision
Apr 23, 2026
Merged

refactor: remove dead DeclaredContract/TypeConstraint infrastructure#14
tob-scott-a merged 1 commit into
mainfrom
declared-contract-decision

Conversation

@tob-scott-a

Copy link
Copy Markdown
Collaborator

DeclaredContract and TypeConstraint were defined in models/annotations.py and exported from models/init.py, but the data they carried was pure redundancy with existing fields on CodeUnit:

  • TypeConstraint(parameter_name, declared_type) == Parameter.name + Parameter.type_ref.name, both already on CodeUnit.
  • DeclaredContract.return_constraint == CodeUnit.return_type.name.
  • DeclaredContract.parameter_types iterates Parameter entries we already have via CodeUnit.parameters.

The 14 tree-sitter parsers all called build_contract(params, return_type) and bound the result to contract, then used it purely as a boolean in if contract is not None: graph.annotations.setdefault(func_id, []). setdefault with an empty list adds nothing observable (preanalysis later prunes empty annotation lists), so the entire pipeline was dead.

Zero consumers in QueryEngine, zero CLI surface, zero skill references. Decision: kill it. If type-level queries become necessary later, they can read Parameter.type_ref and CodeUnit.return_type directly, or a dedicated QueryEngine method can be added then with real semantics.

Removed:

  • models.DeclaredContract, models.TypeConstraint (deleted from annotations.py and the models/init.py exports/all).
  • _common.build_contract (helper and its imports).
  • 14 per-parser contract = build_contract(...) calls and the dead if contract is not None: ... setdefault(...) blocks.
  • The TestContractBuilding test class; the useful sub-assertions (return_type capture, parameter count) moved to TestTypeCapture.

842 tests pass, lint/format/type check clean.

DeclaredContract and TypeConstraint were defined in models/annotations.py
and exported from models/__init__.py, but the data they carried was pure
redundancy with existing fields on CodeUnit:

- TypeConstraint(parameter_name, declared_type) == Parameter.name +
  Parameter.type_ref.name, both already on CodeUnit.
- DeclaredContract.return_constraint == CodeUnit.return_type.name.
- DeclaredContract.parameter_types iterates Parameter entries we
  already have via CodeUnit.parameters.

The 14 tree-sitter parsers all called build_contract(params, return_type)
and bound the result to `contract`, then used it purely as a boolean in
`if contract is not None: graph.annotations.setdefault(func_id, [])`.
setdefault with an empty list adds nothing observable (preanalysis
later prunes empty annotation lists), so the entire pipeline was dead.

Zero consumers in QueryEngine, zero CLI surface, zero skill references.
Decision: kill it. If type-level queries become necessary later, they
can read Parameter.type_ref and CodeUnit.return_type directly, or a
dedicated QueryEngine method can be added then with real semantics.

Removed:
- models.DeclaredContract, models.TypeConstraint (deleted from
  annotations.py and the models/__init__.py exports/__all__).
- _common.build_contract (helper and its imports).
- 14 per-parser `contract = build_contract(...)` calls and the
  dead `if contract is not None: ... setdefault(...)` blocks.
- The TestContractBuilding test class; the useful sub-assertions
  (return_type capture, parameter count) moved to TestTypeCapture.

842 tests pass, lint/format/type check clean.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@tob-scott-a
tob-scott-a merged commit 32efbd6 into main Apr 23, 2026
13 checks passed
@tob-scott-a
tob-scott-a deleted the declared-contract-decision branch April 23, 2026 06:04
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.

1 participant