comparison configmix/config.py @ 350:9d729c479dc2

FIX: Do not apply the type convertion None -> "" if the expansions comprises the whole expression
author Franz Glasner <f.glasner@feldmann-mg.com>
date Thu, 24 Jun 2021 19:22:53 +0200
parents 83f76a41cf7c
children 2b209bdf6995
comparison
equal deleted inserted replaced
349:83f76a41cf7c 350:9d729c479dc2
355 warnings.warn("Cannot expand variable %r in string " 355 warnings.warn("Cannot expand variable %r in string "
356 "%r" % (varname, s, ), 356 "%r" % (varname, s, ),
357 UserWarning, 357 UserWarning,
358 stacklevel=1) 358 stacklevel=1)
359 raise 359 raise
360 if varvalue is None:
361 varvalue = u("")
362 # 360 #
363 # Dont apply and type conversions to str if the whole `s` is 361 # Dont apply and type conversions to the variable value if
364 # just one expansion 362 # the whole `s` is just one expansion
365 # 363 #
366 if (start == 0) and (end + 2 == len(s)): 364 if (start == 0) and (end + 2 == len(s)):
367 return varvalue 365 return varvalue
366 if varvalue is None:
367 varvalue = u("")
368 replaced = s[:start] + u(str(varvalue)) 368 replaced = s[:start] + u(str(varvalue))
369 s = replaced + s[end+2:] 369 s = replaced + s[end+2:]
370 # don't re-evaluate because `self.getvar_s()` expands already 370 # don't re-evaluate because `self.getvar_s()` expands already
371 start = s.find(self._STARTTOK, len(replaced)) 371 start = s.find(self._STARTTOK, len(replaced))
372 return s 372 return s