Gary Oberbrunner committed 8a771d3

Make Action+None and None+Action work as expected (silently ignore the None arg).

  • Participants
  • Parent commits af50c98

Comments (0)

Files changed (3)

File src/CHANGES.txt

+  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

File src/engine/SCons/

     # 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)
         # 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):

File src/engine/SCons/

     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
         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
             sum = act2 + 1
         except TypeError: