Bind Annotation Migration
Summary
The preprocessor has been converted from implicit uppercase binding to explicit Bind annotation. This is a breaking change that requires code updates.
What Changed
Before (Implicit Binding)
from nf.core import App, Stack, Resource
# Automatically wrapped due to uppercase first letter
app = App()
stack = Stack(app)
resource = Resource(type="aws_s3_bucket")
After (Explicit Binding)
from nf.core import App, Stack, Resource, Bind
# Only wrapped with explicit Bind annotation
app: Bind = App()
stack: Bind = Stack(app)
resource: Bind = Resource(type="aws_s3_bucket")
# Not wrapped without Bind
helper = HelperClass() # No automatic wrapping
Key Features
- Full LSP/IDE Support:
Bindpreserves type inference and autocomplete my_vpc: Bind- Type inferred from assignment-
my_vpc: Bind[Vpc]- Explicit type for better IDE support -
Explicit Control: No magic, no surprises - you control what gets bound
-
Better Performance: No unnecessary wrapping of uppercase classes
Migration
Use the provided migration script:
python migrate_to_bind.py libs/netherframe.core/
python migrate_to_bind.py examples/
Implementation Details
Files Modified
libs/netherframe.core/netherframe/core/__init__.py- AddedBindtype with LSP supportlibs/netherframe.core/netherframe/core/preprocessor.py- Rewrote detection logic to useBindannotationlibs/netherframe.core/tests/test_bind_annotation.py- New comprehensive test suitemigrate_to_bind.py- Automated migration script
Removed Features
- Automatic wrapping of uppercase classes
- Automatic wrapping in dictionary literals
- Automatic wrapping in context managers
- Automatic wrapping with walrus operator
Testing
- Created new test suite specifically for Bind annotation behavior
- All Bind tests passing
- Existing tests need updates to use Bind annotation
Next Steps
- Update all remaining test files to use Bind annotation
- Update all example files to use Bind annotation
- Update documentation to explain the new pattern
- Remove old uppercase detection references from codebase