@@ -319,7 +319,7 @@ def __init__(self, section):
319319
320320 def interpolate (self , key , value ):
321321 # short-cut
322- if not self ._cookie in value :
322+ if self ._cookie not in value :
323323 return value
324324
325325 def recursive_interpolate (key , value , section , backtrail ):
@@ -543,7 +543,7 @@ def _interpolate(self, key, value):
543543 except AttributeError :
544544 # not yet: first time running _interpolate(), so pick the engine
545545 name = self .main .interpolation
546- if name == True : # note that "if name:" would be incorrect here
546+ if name is True : # note that "if name:" would be incorrect here
547547 # backwards-compatibility: interpolation=True means use default
548548 name = DEFAULT_INTERPOLATION
549549 name = name .lower () # so that "Template", "template", etc. all work
@@ -942,10 +942,8 @@ def as_bool(self, key):
942942 0
943943 """
944944 val = self [key ]
945- if val == True :
946- return True
947- elif val == False :
948- return False
945+ if val is True or val is False :
946+ return val
949947 else :
950948 try :
951949 if not isinstance (val , string_type ):
@@ -1466,7 +1464,7 @@ def _decode(self, infile, encoding):
14661464 # NOTE: Could raise a ``UnicodeDecodeError``
14671465 return infile .decode (encoding ).splitlines (True )
14681466 for i , line in enumerate (infile ):
1469- if not isinstance (line , unicode ):
1467+ if isinstance (line , str ):
14701468 # NOTE: The isinstance test here handles mixed lists of unicode/string
14711469 # NOTE: But the decode will break on any non-string values
14721470 # NOTE: Or could raise a ``UnicodeDecodeError``
@@ -2175,7 +2173,7 @@ def validate_entry(entry, spec, val, missing, ret_true, ret_false):
21752173 if entry in ('__many__' , '___many___' ):
21762174 # reserved names
21772175 continue
2178- if (not entry in section .scalars ) or (entry in section .defaults ):
2176+ if (entry not in section .scalars ) or (entry in section .defaults ):
21792177 # missing entries
21802178 # or entries from defaults
21812179 missing = True
@@ -2238,9 +2236,9 @@ def validate_entry(entry, spec, val, missing, ret_true, ret_false):
22382236 section .inline_comments [entry ] = configspec .inline_comments .get (entry , '' )
22392237 check = self .validate (validator , preserve_errors = preserve_errors , copy = copy , section = section [entry ])
22402238 out [entry ] = check
2241- if check == False :
2239+ if check is False :
22422240 ret_true = False
2243- elif check == True :
2241+ elif check is True :
22442242 ret_false = False
22452243 else :
22462244 ret_true = False
@@ -2356,15 +2354,15 @@ def flatten_errors(cfg, res, levels=None, results=None):
23562354 # first time called
23572355 levels = []
23582356 results = []
2359- if res == True :
2357+ if res is True :
23602358 return results
2361- if res == False or isinstance (res , Exception ):
2359+ if res is False or isinstance (res , Exception ):
23622360 results .append ((levels [:], None , res ))
23632361 if levels :
23642362 levels .pop ()
23652363 return results
23662364 for (key , val ) in res .items ():
2367- if val == True :
2365+ if val is True :
23682366 continue
23692367 if isinstance (cfg .get (key ), dict ):
23702368 # Go down one level
0 commit comments