Skip to content

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

  1. Full LSP/IDE Support: Bind preserves type inference and autocomplete
  2. my_vpc: Bind - Type inferred from assignment
  3. my_vpc: Bind[Vpc] - Explicit type for better IDE support

  4. Explicit Control: No magic, no surprises - you control what gets bound

  5. 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

  1. libs/netherframe.core/netherframe/core/__init__.py - Added Bind type with LSP support
  2. libs/netherframe.core/netherframe/core/preprocessor.py - Rewrote detection logic to use Bind annotation
  3. libs/netherframe.core/tests/test_bind_annotation.py - New comprehensive test suite
  4. migrate_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

  1. Update all remaining test files to use Bind annotation
  2. Update all example files to use Bind annotation
  3. Update documentation to explain the new pattern
  4. Remove old uppercase detection references from codebase