diff options
author | Gary Oberbrunner <garyo@oberbrunner.com> | 2011-02-27 21:54:48 (GMT) |
---|---|---|
committer | Gary Oberbrunner <garyo@oberbrunner.com> | 2011-02-27 21:54:48 (GMT) |
commit | 925ece49f121303e558f9d63b1c138f814465fc8 (patch) | |
tree | fc36afada1d042bbba82f87f85e019bfb6b35574 /src | |
parent | e123fce835056a1e75c6630fe146bb7d45b19970 (diff) | |
download | SCons-925ece49f121303e558f9d63b1c138f814465fc8.zip SCons-925ece49f121303e558f9d63b1c138f814465fc8.tar.gz SCons-925ece49f121303e558f9d63b1c138f814465fc8.tar.bz2 |
Make Action+None and None+Action work as expected (silently ignore the None arg).
Diffstat (limited to 'src')
-rw-r--r-- | src/CHANGES.txt | 3 | ||||
-rw-r--r-- | src/engine/SCons/Action.py | 10 | ||||
-rw-r--r-- | src/engine/SCons/ActionTests.py | 15 |
3 files changed, 24 insertions, 4 deletions
diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 6278f2e..f49c9af 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -7,6 +7,9 @@ RELEASE 2.1.0.alpha.yyyymmdd - NEW DATE WILL BE INSERTED HERE + From Gary Oberbrunner: + - Adding None to an Action no longer fails (just returns original action) + From David Garcia Garzon: - Fix Delete to be able to delete broken symlinks and dir symlinks. diff --git a/src/engine/SCons/Action.py b/src/engine/SCons/Action.py index bb23287..0dc5c2d 100644 --- a/src/engine/SCons/Action.py +++ b/src/engine/SCons/Action.py @@ -300,8 +300,10 @@ def _actionAppend(act1, act2): # a single ListAction. a1 = Action(act1) a2 = Action(act2) - if a1 is None or a2 is None: - raise TypeError("Cannot append %s to %s" % (type(act1), type(act2))) + if a1 is None: + return a2 + if a2 is None: + return a1 if isinstance(a1, ListAction): if isinstance(a2, ListAction): return ListAction(a1.list + a2.list) @@ -385,6 +387,10 @@ def _do_create_action(act, kw): # The list of string commands may include a LazyAction, so we # reprocess them via _do_create_list_action. return _do_create_list_action(commands, kw) + # Catch a common error case with a nice message: + if isinstance(act, int) or isinstance(act, float): + raise TypeError("Don't know how to create an Action from a number (%s)"%act) + # Else fail silently (???) return None def _do_create_list_action(act, kw): diff --git a/src/engine/SCons/ActionTests.py b/src/engine/SCons/ActionTests.py index 02407cc..13c3b6c 100644 --- a/src/engine/SCons/ActionTests.py +++ b/src/engine/SCons/ActionTests.py @@ -397,8 +397,12 @@ class ActionTestCase(unittest.TestCase): def test_no_action(self): """Test when the Action() factory can't create an action object """ - a5 = SCons.Action.Action(1) - assert a5 is None, a5 + try: + a5 = SCons.Action.Action(1) + except TypeError: + pass + else: + assert 0, "Should have thrown a TypeError creating Action from an int." def test_reentrance(self): """Test the Action() factory when the action is already an Action object @@ -802,6 +806,13 @@ class _ActionActionTestCase(unittest.TestCase): assert isinstance(sum.list[2], SCons.Action.CommandGeneratorAction) assert isinstance(sum.list[3], SCons.Action.FunctionAction) + # OK to add None on either side (should be ignored) + sum = act1 + None + assert sum == act1 + + sum = None + act1 + assert sum == act1 + try: sum = act2 + 1 except TypeError: |