Merge pull request #373 from puremourning/fix-calculus
Fix default variable values having substitutions from the calculus
This commit is contained in:
commit
af2670ef9a
2 changed files with 7 additions and 3 deletions
|
|
@ -494,7 +494,6 @@ def _Substitute( template, mapping ):
|
|||
if mo.group( 'braceddefault' ) is not None:
|
||||
named = mo.group( 'defname' )
|
||||
if named not in mapping:
|
||||
''
|
||||
raise MissingSubstitution(
|
||||
named,
|
||||
mo.group( 'default' ).replace( '\\}', '}' ) )
|
||||
|
|
@ -536,8 +535,11 @@ def ExpandReferencesInString( orig_s,
|
|||
if default_value is None and e.default_value is not None:
|
||||
try:
|
||||
default_value = _Substitute( e.default_value, mapping )
|
||||
except MissingSubstitution:
|
||||
default_value = e.default_value
|
||||
except MissingSubstitution as e2:
|
||||
if e2.name in calculus:
|
||||
default_value = calculus[ e2.name ]()
|
||||
else:
|
||||
default_value = e.default_value
|
||||
|
||||
mapping[ key ] = AskForInput( 'Enter value for {}: '.format( key ),
|
||||
default_value )
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ class TestExpandReferencesInDict( unittest.TestCase ):
|
|||
'one': '${one}',
|
||||
'two': '${one} and ${two}',
|
||||
'three': '${three}',
|
||||
'three_with_default': '${three_with_default:${three\\}}', # uses calculus
|
||||
'four': '${four}',
|
||||
'five': '${five}',
|
||||
'list': [ '*${words}' ],
|
||||
|
|
@ -58,6 +59,7 @@ class TestExpandReferencesInDict( unittest.TestCase ):
|
|||
'one': 'one',
|
||||
'two': 'one and TWO',
|
||||
'three': '3',
|
||||
'three_with_default': '3',
|
||||
'four': 'typed text',
|
||||
'five': '5ive!',
|
||||
'list': [ 'these', 'are', 'some', 'words' ],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue