Gary Oberbrunner avatar Gary Oberbrunner committed 8a771d3

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

Comments (0)

Files changed (3)

 
 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.

src/engine/SCons/Action.py

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

src/engine/SCons/ActionTests.py

     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
+
         try:
             sum = act2 + 1
         except TypeError:
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.