Skip to content

Normalize attribute template/bounds pairs to tuples - #235

Open
kroenlein wants to merge 1 commit into
mainfrom
tuple-attribute-pairs
Open

kroenlein wants to merge 1 commit into
mainfrom
tuple-attribute-pairs

Conversation

@kroenlein

@kroenlein kroenlein commented Sep 28, 2026 •

Copy link
Copy Markdown
Collaborator

A quick follow on to #233 that consolidates type definitions to aid code readability. The clean up demonstrated ways in which the typing was subtly wrong, and so this includes changing the actual return and storage type of Template-Bounds pairs to tuples instead of lists. This should be transparent for nearly all workflows, barring if users were directly editing the tuples (a tuple is immutable).

Return the (template, bounds) pair from BaseTemplate._homogenize_ranges as a
tuple rather than a list, and introduce type aliases so every annotation in
the template modules states what the code actually accepts and returns.

Each module now declares the same four aliases: the template or its link, the
canonical pair as a tuple, the same pair spelled as a list, and the union of
everything the setters take. Collapsing the nested unions into these aliases
removes the six-line annotations that the formatter had exploded.

Correct three annotations that the aliases exposed. The conditions and
parameters getters claimed to return bare templates when they return pairs.
The input annotations omitted the list form, which is not merely tolerated:
JSON arrays deserialize to lists, so every load path supplies the pair that
way.

This changes observable behavior. Pairs read back from a template are now
immutable, so code that assigned to one element must replace the pair
instead:

    template.conditions[0][1] = None                        # before
    template.conditions[0] = (template.conditions[0][0], None)  # after

Objects built by earlier versions hold list pairs and do not compare equal to
objects built by this one. Data persisted as JSON is unaffected, since the
pair is rebuilt on load. The serialized form is byte-identical either way.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@kroenlein
kroenlein marked this pull request as ready for review September 28, 2026 23:03

This branch has not been deployed

No deployments
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