Skip to content

Conversation

@ducky64
Copy link
Collaborator

@ducky64 ducky64 commented Nov 10, 2025

Moves the __init__ hook into a metaclass hook on __init__ instead of the previously explicit @init_in_parent decorator. Cleans up the hook logic. Deprecates @init_in_parent.

It seems this must be an __init__ hook of some kind, since it needs to inspect each super().__init__ call, recursively, with the context it is called in. The __init__ hook does double duty:

  • For the top-level block being elaborated, it materializes missing params with dummy values
  • For inner blocks, it 'wraps' arg values by creating a param based on the type annotation

Internally, removes the Block._init_param_values, which used to be the source of truth for init values. Instead, init params have an InitParamBinding, which stores the value, if any

This changes (fixes, imo) some behavior:

  • No longer materializes missing params except for the top-level block. Calls to blocks that are missing params will now fail, as expected.
  • *Expr (eg, RangeExpr, FloatExpr) are no longer allowed as annotation types, instead must use *Like (eg, RangeLike, FloatLike)

Removes @init_in_parent in all the library code. There's a bunch. Fixes some libraries which are broken. Removes obsoleted unit tests.

Adds a dead-simple LED test, probably the simplest possible circuit here.

Resolves #409

@ducky64 ducky64 requested a review from Copilot November 10, 2025 08:48
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR removes the @init_in_parent decorator from all Block __init__ methods and replaces it with a metaclass-based approach. The new BlockMeta metaclass automatically hooks into every Block's __init__ to handle parameter transformations, eliminating the need for the decorator. The PR also includes deprecation warnings for any remaining uses of the decorator, updates error messages, and fixes some type annotations and comments.

Key Changes

  • Introduces BlockMeta metaclass in HierarchyBlock.py to automatically handle init parameter transformations
  • Removes all @init_in_parent decorator usage across ~170+ files
  • Updates InitParamBinding to store the parameter value
  • Fixes type annotations in some files (e.g., RangeExprRangeLike)
  • Updates TODO comments and error messages

Reviewed Changes

Copilot reviewed 147 out of 147 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
edg/core/HierarchyBlock.py Implements BlockMeta metaclass, deprecates init_in_parent decorator
edg/core/Binding.py Adds value storage to InitParamBinding
edg/core/test_default.py Updates test class names and adds new test cases
edg/abstract_parts/AbstractCapacitor.py Adds required parameters to CombinedCapacitorElement instantiation
examples/test_fcml.py Fixes type annotations from RangeExpr to RangeLike
edg/electronics_model/PassivePort.py Updates TODO comments
All other files Removes @init_in_parent decorators

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +351 to +352
self.elements = self.PackedPart(PackedBlockArray(CombinedCapacitorElement(capacitance=RangeExpr(),
voltage=RangeExpr())))
Copy link

Copilot AI Nov 10, 2025

Choose a reason for hiding this comment

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

The CombinedCapacitorElement is being instantiated with RangeExpr() for capacitance and voltage parameters. With the new metaclass approach, these should be passed as unbound parameters (no arguments), not empty RangeExpr() instances. This may cause issues since the metaclass expects to transform the arguments. Consider removing the explicit RangeExpr() calls or ensuring they are properly handled by the new metaclass.

Suggested change
self.elements = self.PackedPart(PackedBlockArray(CombinedCapacitorElement(capacitance=RangeExpr(),
voltage=RangeExpr())))
self.elements = self.PackedPart(PackedBlockArray(CombinedCapacitorElement(capacitance=RangeExpr,
voltage=RangeExpr)))

Copilot uses AI. Check for mistakes.
@ducky64 ducky64 merged commit 0634299 into master Nov 10, 2025
18 of 19 checks passed
@ducky64 ducky64 deleted the noinitinparent branch November 10, 2025 08:59
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.

Remove init_in_parent

2 participants