diff --git a/builders/construct.py b/builders/construct.py index ca7d176..cc162b8 100644 --- a/builders/construct.py +++ b/builders/construct.py @@ -225,9 +225,11 @@ def __init__(self, construct, enabled=False): self.default = enabled def doBuild(self, *args, **kwargs): - if self.enabled: - return self.construct.doBuild(*args, **kwargs) - self.enabled = self.default + try: + if self.enabled: + return self.construct.doBuild(*args, **kwargs) + finally: + self.enabled = self.default class Uplink(Construct): diff --git a/builders/info.py b/builders/info.py index 60d35d8..897dcba 100644 --- a/builders/info.py +++ b/builders/info.py @@ -6,5 +6,5 @@ @author: pupssman ''' -__version__ = '1.2.6' +__version__ = '1.2.7' __package_name__ = 'builders' diff --git a/builders/tests/test_modifiers.py b/builders/tests/test_modifiers.py index 7f2fafc..2456bc0 100644 --- a/builders/tests/test_modifiers.py +++ b/builders/tests/test_modifiers.py @@ -290,3 +290,17 @@ class B: assert b1.a is None assert b2.a + + +def test_maybe_enabled(): + class A: + pass + + class B: + a = Maybe(Unique(A)) + + b1 = Builder(B).withA(Enabled(B.a)).build() + b2 = Builder(B).build() + + assert b1.a is not None + assert b2.a is None