Skip to content

Type quantum-number maps and rule signatures with TypedDict #337

Description

@redeboer

Spike to validate typing the quantum-number property maps and rule signatures with TypedDict, instead of the current NewType-key plus attrs-input-class machinery. The present typing predates TypedDict and has already capitulated: EdgeQuantumNumberTypes = Any under TYPE_CHECKING, and the property maps are dict[Any, Scalar] (src/qrules/quantum_numbers.py:130-153, src/qrules/argument_handling.py:39-43).

Prototype EdgeFacts / NodeFacts as TypedDict(total=False) with real per-key value types, migrate two or three representative rules (spin_magnitude_conservation, helicity_conservation, and one additive rule) to take TypedDict-subset parameters, and derive rule requirements from __required_keys__ / __optional_keys__ instead of get_required_qns and _CompositeArgumentCheck (src/qrules/argument_handling.py:177-336).

Acceptance gate: ty verifies the structural subtyping (flags a rule called with facts missing a required key), and the CSP loop does not regress versus the current per-evaluation attrs construction in _CompositeArgumentCreator (src/qrules/argument_handling.py:137-156); benchmark against a tests/channels reaction. If the gate fails, the remaining work can still proceed on the existing NewType representation.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

🔨 MaintenanceMaintenance and upkeep improvements🖱️ DXImprovements to the Developer Experience

Type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions