Skip to content

Tie feature labels to variable names so they can't silently drift (uses 3.12 and 3.14)#644

Draft
audreyfeldroy wants to merge 1 commit intomainfrom
modern-python
Draft

Tie feature labels to variable names so they can't silently drift (uses 3.12 and 3.14)#644
audreyfeldroy wants to merge 1 commit intomainfrom
modern-python

Conversation

@audreyfeldroy
Copy link
Copy Markdown
Collaborator

Feature labels are now variable names. The 23-element feature vector is destructured into named variables, and a Python 3.14 template string passes them to _render_features(). The function walks the template interpolations and emits name=value pairs using each interpolation's .expression attribute. There is no separate name list to maintain, so labels can't go stale when features are added or reordered.

Key design decisions:

  • type FeatureVector = list[float] (Python 3.12) gives the feature vector a first-class name in the type system
  • Native str | bytes | Path union syntax for public API signatures
  • tree.py imports FeatureVector under TYPE_CHECKING to avoid circular imports at runtime
  • The 23-line feature index docstring in _compute_features is removed; the destructuring assignment is the index

Requires Python 3.14+ for t-strings. Putting this on hold for now; currently considering the support-python-310 branch to serve cookieplone users who need the older floor.

Feature labels are now variable names. The 23-element feature vector
is destructured into named variables, and a Python 3.14 template
string passes them to _render_features(). The function walks the
template interpolations and emits name=value pairs using each
interpolation's .expression attribute. There is no separate name list
to maintain, so labels can't go stale when features are added or
reordered.

Key design decisions:
- type FeatureVector = list[float] (Python 3.12) gives the feature
  vector a first-class name in the type system
- Native str | bytes | Path union syntax for public API signatures
- tree.py imports FeatureVector under TYPE_CHECKING to avoid circular
  imports at runtime
- The 23-line feature index docstring in _compute_features is removed;
  the destructuring assignment is the index

Requires Python 3.14+ for t-strings. The support-python-310 branch
serves users who need the older floor.
@audreyfeldroy audreyfeldroy changed the title Tie feature labels to variable names so they can't silently drift Tie feature labels to variable names so they can't silently drift (uses 3.12 and 3.14) Mar 8, 2026
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