-
Notifications
You must be signed in to change notification settings - Fork 12
Eliminate @init_in_parent #431
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this 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
BlockMetametaclass inHierarchyBlock.pyto automatically handle init parameter transformations - Removes all
@init_in_parentdecorator usage across ~170+ files - Updates
InitParamBindingto store the parameter value - Fixes type annotations in some files (e.g.,
RangeExpr→RangeLike) - 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.
| self.elements = self.PackedPart(PackedBlockArray(CombinedCapacitorElement(capacitance=RangeExpr(), | ||
| voltage=RangeExpr()))) |
Copilot
AI
Nov 10, 2025
There was a problem hiding this comment.
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.
| self.elements = self.PackedPart(PackedBlockArray(CombinedCapacitorElement(capacitance=RangeExpr(), | |
| voltage=RangeExpr()))) | |
| self.elements = self.PackedPart(PackedBlockArray(CombinedCapacitorElement(capacitance=RangeExpr, | |
| voltage=RangeExpr))) |
Moves the
__init__hook into a metaclass hook on__init__instead of the previously explicit@init_in_parentdecorator. 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 eachsuper().__init__call, recursively, with the context it is called in. The__init__hook does double duty: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 anyThis changes (fixes, imo) some behavior:
Removes
@init_in_parentin 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