From b9118b02f855f4613ee5a43b67da29b5895c4f03 Mon Sep 17 00:00:00 2001 From: Jason Toffaletti Date: Tue, 7 Feb 2017 18:05:53 -0800 Subject: [PATCH] [gyb] check isinstance(result, basestring) before string comparison Guard against types that override __eq__ and do things like raise TypeError when the types being compared don't match. --- utils/gyb.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/utils/gyb.py b/utils/gyb.py index e7bbf895035a8..3d5254c8d5419 100755 --- a/utils/gyb.py +++ b/utils/gyb.py @@ -15,6 +15,11 @@ from bisect import bisect +try: + basestring +except NameError: + basestring = str + def get_line_starts(s): """Return a list containing the start index of each line in s. @@ -716,7 +721,8 @@ def execute(self, context): # If we got a result, the code was an expression, so append # its value - if result is not None and result != '': + if result is not None \ + or (isinstance(result, basestring) and result != ''): from numbers import Number, Integral result_string = None if isinstance(result, Number) and not isinstance(result, Integral):