Skip to content

Commit

Permalink
Make Action+None and None+Action work as expected (silently ignore th…
Browse files Browse the repository at this point in the history
…e None arg).
  • Loading branch information
Gary Oberbrunner committed Feb 27, 2011
1 parent 92e4689 commit 0102800
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 8 additions & 2 deletions src/engine/SCons/Action.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down
15 changes: 13 additions & 2 deletions src/engine/SCons/ActionTests.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,12 @@ def lazy_action(a):
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
Expand Down Expand Up @@ -802,6 +806,13 @@ def bar():
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:
Expand Down

0 comments on commit 0102800

Please sign in to comment.