Skip to content

MetaClasses: keep a class' slot initial values of its whole hierarchy - #553

Merged
Paebbels merged 1 commit into
devfrom
claude/slot-defaults-inherited
Oct 12, 2026
Merged

Paebbels merged 1 commit into
devfrom
claude/slot-defaults-inherited

Conversation

@pytooling-claude

Copy link
Copy Markdown

Changes

  • ExtendedType._wrapInitMethodIfSlotDefaults (MetaClasses: assign a slotted field's initial value in an intermediate __init__ #524, MetaClasses: assign slot initial values without probing each field #544) walked the whole method resolution order of every new
    class to collect the initial values of slotted fields, also in hierarchies without any. Each class now keeps them in
    the class field __allSlotDefaults__, merged from its direct base-classes' mappings and its own __slotDefaults__,
    and returns right away when the mapping is empty.
  • The wrapper's semantics are unchanged: the outermost class assigns the values through the slots' descriptors before
    any __init__ runs, a mixin-class' field in a class without slots goes to __dict__, a derived class wraps the
    base-class' original __init__.
  • __allSlotDefaults__ is listed in ExtendedType's field list.

Measurements

Only the changed step, PYTHONPATH pinned to each checkout, taskset -c 6:

_wrapInitMethodIfSlotDefaults, leaf class with an MRO of 14, no initial values before after
Python 3.14 3.31 µs 1.00 µs
Python 3.13 1.77 µs 0.62 µs

During pyVHDLModel's import (412 classes, none with initial values; Python 3.13), the step takes 0.57 ms instead of
0.87 ms. That is about 1 % of the time spent in ExtendedType.__new__, below the run-to-run noise of the whole import.

Documentation

Unit Tests

  • tests/unit/MetaClasses/ObjectVariable.py: __allSlotDefaults__ of a mixin-class, an intermediate class and a
    class mixing both; a hierarchy without initial values keeps its own __init__.
  • tests/unit: 2521 passed, 31 skipped, 3 xfailed.

Related Issues and Pull-Requests

_wrapInitMethodIfSlotDefaults walked the whole MRO of every class to
collect the initial values of slotted fields, also in hierarchies
without any. Each class now keeps them in __allSlotDefaults__, merged
from its direct base-classes' mappings and its own __slotDefaults__, and
returns right away if the mapping is empty.

The wrapper's semantics are unchanged.

Co-Authored-By: Patrick Lehmann <Paebbels@gmail.com>
@pytooling-claude
pytooling-claude Bot requested a review from Paebbels as a code owner October 12, 2026 00:17
@pytooling-claude pytooling-claude Bot added the MetaClass Generally about meta-classes. label Oct 12, 2026
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

Metric Results
Complexity 0
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@Paebbels
Paebbels merged commit 63981f7 into dev Oct 12, 2026
16 of 44 checks passed
This was referenced Oct 20, 2026
@pytooling-claude pytooling-claude Bot added this to the v10.0 milestone Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

MetaClass Generally about meta-classes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants