From 0cd63a22578d0f339ac8573f96fddb192e509863 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carn=C3=AB=20Draug?= Date: Fri, 15 Feb 2013 05:00:53 +0000 Subject: Allow NoneType for CheckContext.Result --- src/engine/SCons/SConf.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/engine/SCons/SConf.py b/src/engine/SCons/SConf.py index 0506f80..584c433 100644 --- a/src/engine/SCons/SConf.py +++ b/src/engine/SCons/SConf.py @@ -35,6 +35,7 @@ import os import re import sys import traceback +import types import SCons.Action import SCons.Builder @@ -776,11 +777,12 @@ class CheckContext(object): self.did_show_result = 0 def Result(self, res): - """Inform about the result of the test. res may be an integer or a - string. In case of an integer, the written text will be 'yes' or 'no'. - The result is only displayed when self.did_show_result is not set. + """Inform about the result of the test. res may be an integer, a + string, or a boolean. In case of an integer, the written text will be + 'yes' or 'no'. The result is only displayed when self.did_show_result + is not set. """ - if isinstance(res, (int, bool)): + if isinstance(res, (int, bool, types.NoneType)): if res: text = "yes" else: -- cgit v0.12 From ede4ee9b3306ca546c2f04bcabff9f970ed1cb9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carn=C3=AB=20Draug?= Date: Sat, 2 Mar 2013 21:27:24 +0000 Subject: Do not check for result type in CheckContext.Result, support duck typing --- src/engine/SCons/SConf.py | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/engine/SCons/SConf.py b/src/engine/SCons/SConf.py index 584c433..f3a3545 100644 --- a/src/engine/SCons/SConf.py +++ b/src/engine/SCons/SConf.py @@ -35,7 +35,6 @@ import os import re import sys import traceback -import types import SCons.Action import SCons.Builder @@ -777,20 +776,16 @@ class CheckContext(object): self.did_show_result = 0 def Result(self, res): - """Inform about the result of the test. res may be an integer, a - string, or a boolean. In case of an integer, the written text will be - 'yes' or 'no'. The result is only displayed when self.did_show_result - is not set. + """Inform about the result of the test. If res is not a string, displays + 'yes' or 'no' depending on whether res is evaluated as true or false. + The result is only displayed when self.did_show_result is not set. """ - if isinstance(res, (int, bool, types.NoneType)): - if res: - text = "yes" - else: - text = "no" - elif isinstance(res, str): + if isinstance(res, str): text = res + elif res: + text = "yes" else: - raise TypeError("Expected string, int or bool, got " + str(type(res))) + text = "no" if self.did_show_result == 0: # Didn't show result yet, do it now. -- cgit v0.12