Skip to content

Add core helpers: shortest_decimal, EnumConverter, own_annotations - #308

Merged
balbasty merged 1 commit into
mainfrom
claude/feat/233-core-helpers
Oct 6, 2026
Merged

balbasty merged 1 commit into
mainfrom
claude/feat/233-core-helpers

Conversation

@balbasty

@balbasty balbasty commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Part of #233, split out of #287. Stacked on #307: EnumConverter's docstring example uses SpaceEnum.

Small general-purpose helpers in brainhops._core:

  • numeric.shortest_decimal(value, encode) (and float32_repr): the shortest decimal that a writer would store as the same float32 after encode. For example, an MGH TR stored as float32 milliseconds reads back as 2.0007 s rather than 2.000699951171875.
  • enum.EnumConverter(enum): a field converter that accepts members, values or names. Unlike a closure, it has a repr, compares equal and pickles.
  • compat.own_annotations(cls): a class's own annotations on Python 3.8 to 3.14, under PEP 649 lazy annotations.
  • compare.differs.
  • A docstring and __all__ for properties.py.

Also adds the tests (tests/test_core_numeric.py) and the docs/api/_core pages and nav entries.

Stack

  1. Design memo for the format-metadata framework #306: design memo
  2. Add vocabulary enums for spaces, intents, manufacturers and microscopy #307: vocabulary enums
  3. this PR: core helpers, stacked on Add vocabulary enums for spaces, intents, manufacturers and microscopy #307
  4. FormatDispatcher mixin and small fixes, based on main
  5. The metadata system, stacked on 1–4
  6. Wire format metadata into images and transformations (#233) #287: wiring, stacked on 5

🤖 Generated with Claude Code

https://claude.ai/code/session_01VmK1jLTwd2hMkvYnMWEyYw


Generated by Claude Code

- _core/numeric.py: shortest_decimal, the shortest decimal that a file
  stores as the same single-precision number (through an optional unit
  conversion), and float32_repr.
- _core/enum.py: EnumConverter, the converter of a free-text field with
  known terms (a known term becomes the enum member, any other string
  stays a string).
- _core/compat.py: own_annotations, the annotations a class declares
  itself, read portably on Python 3.14 (PEP 649/749).
- _core/compare.py: differs, which does not trust != on arrays.
- _core/properties.py: a module docstring and __all__.

With tests for the numeric helpers, and API pages for properties,
numeric and enum. Stacked on the vocabulary enums, which the
EnumConverter example uses (SpaceEnum).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VmK1jLTwd2hMkvYnMWEyYw
Base automatically changed from claude/feat/233-vocabulary-enums to main October 6, 2026 05:39
@balbasty
balbasty merged commit e627249 into main Oct 6, 2026
5 checks passed
@balbasty
balbasty deleted the claude/feat/233-core-helpers branch October 6, 2026 05:46
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.

2 participants