From d9e82a259560def043ac8d8e1251e0fe0b049d46 Mon Sep 17 00:00:00 2001 From: stevenknight Date: Sat, 28 Dec 2002 07:59:31 +0000 Subject: [PATCH] Have the Environment.get() method return None as the default, like the standard Python get() method. (Lachlan O'Dea) git-svn-id: http://scons.tigris.org/svn/scons/trunk@532 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- src/CHANGES.txt | 4 ++++ src/engine/SCons/Environment.py | 2 +- src/engine/SCons/EnvironmentTests.py | 13 +++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/CHANGES.txt b/src/CHANGES.txt index eebe7666..a02dc5c3 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -30,6 +30,10 @@ RELEASE 0.10 - XXX - Add a Clean() method to support removing user-specified targets when using the -c option. + From Lachlan O'Dea: + + - Make the Environment.get() method return None by default. + From Anthony Roach: - Add SetJobs() and GetJobs() methods to allow configuration of the diff --git a/src/engine/SCons/Environment.py b/src/engine/SCons/Environment.py index 480169e7..8861a99e 100644 --- a/src/engine/SCons/Environment.py +++ b/src/engine/SCons/Environment.py @@ -457,7 +457,7 @@ class Environment: else: return self - def get(self, key, default): + def get(self, key, default=None): "Emulates the get() method of dictionaries.""" return self._dict.get(key, default) diff --git a/src/engine/SCons/EnvironmentTests.py b/src/engine/SCons/EnvironmentTests.py index 0d0d7da9..ff894247 100644 --- a/src/engine/SCons/EnvironmentTests.py +++ b/src/engine/SCons/EnvironmentTests.py @@ -683,6 +683,19 @@ class EnvironmentTestCase(unittest.TestCase): assert env['TOOL2'] == 222, env assert env['AAA'] == 'aaa', env + def test_get(self): + """Test the get() method.""" + env = Environment(aaa = 'AAA') + + x = env.get('aaa') + assert x == 'AAA', x + x = env.get('aaa', 'XXX') + assert x == 'AAA', x + x = env.get('bbb') + assert x is None, x + x = env.get('bbb', 'XXX') + assert x == 'XXX', x + if __name__ == "__main__": suite = unittest.makeSuite(EnvironmentTestCase, 'test_') if not unittest.TextTestRunner().run(suite).wasSuccessful(): -- 2.26.2