Skip to content

Run on metaclass-registry 0.4: one owner per registry key - #18

Merged
trissim merged 3 commits into
mainfrom
fix/metaclass-registry-0.4
Oct 12, 2026
Merged

trissim merged 3 commits into
mainfrom
fix/metaclass-registry-0.4

Conversation

@trissim

@trissim trissim commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

metaclass-registry 0.4 refuses a second class under a registered key. NRA failed at import:

DuplicateRegistryKeyError: witness name alias mixin key AliasProperty(source_name='class_name') is already registered to ...ClassNameWitnessNameMixin; ...ClassLineWitnessCandidate cannot register under the same key.

Where the defect was

WitnessNameAliasMixin declared its own AutoRegisterMeta family keyed by the witness_name descriptor. Nothing reads that registry. Each line witness inheriting ClassNameWitnessNameMixin or QualnameWitnessNameMixin inherited the mixin's key, so 19 classes claimed 2 keys; under 0.3 each silently displaced the last. A probe that records every refused registration instead of raising found these 19 and no others across all NRA modules.

Fix

  • The mixin is a plain ABC that supplies witness_name. Each witness registers once, in LineWitnessCandidate, under its own class-name key. No __replaces_registered__: no class replaces another.
  • AutoRegisterClassAuthority.require_requested_key_compatibility builds requested members through the real metaclass. Two classes requested under one key now raise the library's error there; it is translated to the same ValueError the callers already handle.
  • metaclass-registry>=0.4.0; uv.lock regenerated.

Tests

tests/test_registry_keys_have_one_owner.py: every class of every NRA family holds one key; the mixins register nothing; the requested-key check refuses a key claimed twice.

🤖 Generated with Claude Code

trissim and others added 2 commits October 12, 2026 10:12
WitnessNameAliasMixin declared an AutoRegisterMeta family keyed by the
witness_name descriptor. Nothing reads that registry. Every line witness
that inherits ClassNameWitnessNameMixin or QualnameWitnessNameMixin
inherited the mixin's key, so 19 classes claimed two keys between them and
each displaced the last; a class listing the mixin first also never reached
the LineWitnessCandidate registry. metaclass-registry 0.4 rejects the
second claim at import.

The mixin is now a plain ABC that supplies witness_name. Each witness
registers once, in LineWitnessCandidate, under its own class-name key.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…istry 0.4

require_requested_key_compatibility builds the requested members through
the real AutoRegisterMeta and compares the registry with the request. Two
different classes asked for under one key used to overwrite each other and
fail that comparison; 0.4 refuses the second class itself, with an error
that is not a ValueError and so escaped the callers' handling.

Translate it to the same ValueError. Tests: each class of every NRA family
holds one key; the witness-name mixins register nothing; the requested-key
check refuses a key claimed twice.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 12, 2026 14:26

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

…rites

The type-keyed descent test executed a fixture in which a subclass inherits
its parent's key and takes it over. 0.4 refuses that class at its
declaration, so the test now asserts the refusal and that the key keeps its
owner; the codemod's static rejection is asserted as before.

The one-key-per-class guard walks classes by identity, because other tests
declare unhashable classes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@trissim
trissim force-pushed the fix/metaclass-registry-0.4 branch from 2cf77e4 to 42b83b2 Compare October 12, 2026 15:06
@trissim
trissim merged commit cb6942a into main Oct 12, 2026
1 of 7 checks passed
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