proboscis / pinjected

MIT License
10 stars 0 forks source link

Make runnable Injected be overridable with 'with' block #17

Closed proboscis closed 2 months ago

proboscis commented 4 months ago

This is a proposal to specify 'overrides' for injected variables defined in a module.

# test_module.py
with providers(x=1):
    y = injected('x')
    with providers(x=2, z=3):
        alpha = injected('x') + injected('z')
% pinjected run test_module.y # -> '1'
% pinjected run test_module.alpha # -> '5'
proboscis commented 4 months ago

Choices:

with override(providers()):

or

with providers():
proboscis commented 4 months ago

I prefer with providers(), but this will involve modification to Design class, affecting the semantics of the Design.

proboscis commented 2 months ago

Implemented with #20 , closing.