@@ -387,7 +387,10 @@ def __init__(self, completekey: str = 'tab', stdin=None, stdout=None, *,
387
387
self .settable = \
388
388
{
389
389
# allow_ansi is a special case in which it's an application-wide setting defined in ansi.py
390
- 'allow_ansi' : 'Allow ANSI escape sequences in output (valid values: Terminal, Always, Never)' ,
390
+ 'allow_ansi' : ('Allow ANSI escape sequences in output '
391
+ '(valid values: {}, {}, {})' .format (ansi .ANSI_TERMINAL ,
392
+ ansi .ANSI_ALWAYS ,
393
+ ansi .ANSI_NEVER )),
391
394
'continuation_prompt' : 'On 2nd+ line of input' ,
392
395
'debug' : 'Show full error stack on error' ,
393
396
'echo' : 'Echo command issued into output' ,
@@ -561,7 +564,11 @@ def allow_ansi(self) -> str:
561
564
@allow_ansi .setter
562
565
def allow_ansi (self , new_val : str ) -> None :
563
566
"""Read-only property needed to support do_set when it sets allow_ansi"""
564
- ansi .allow_ansi = new_val
567
+ if new_val not in (ansi .ANSI_TERMINAL , ansi .ANSI_ALWAYS , ansi .ANSI_NEVER ):
568
+ self .perror ('Invalid value: {} (valid values: {}, {}, {})' .format (new_val , ansi .ANSI_TERMINAL ,
569
+ ansi .ANSI_ALWAYS , ansi .ANSI_NEVER ))
570
+ else :
571
+ ansi .allow_ansi = new_val
565
572
566
573
@property
567
574
def visible_prompt (self ) -> str :
@@ -2953,17 +2960,20 @@ def do_set(self, args: argparse.Namespace) -> None:
2953
2960
return self ._show (args , param )
2954
2961
2955
2962
# Update the settable's value
2956
- current_value = getattr (self , param )
2957
- value = utils .cast (current_value , value )
2958
- setattr (self , param , value )
2963
+ orig_value = getattr (self , param )
2964
+ setattr (self , param , utils .cast (orig_value , value ))
2965
+
2966
+ # In cases where a Python property is used to validate and update a settable's value, its value will not
2967
+ # change if the passed in one is invalid. Therefore we should read its actual value back and not assume.
2968
+ new_value = getattr (self , param )
2959
2969
2960
- self .poutput ('{} - was: {}\n now: {}' .format (param , current_value , value ))
2970
+ self .poutput ('{} - was: {}\n now: {}' .format (param , orig_value , new_value ))
2961
2971
2962
2972
# See if we need to call a change hook for this settable
2963
- if current_value != value :
2973
+ if orig_value != new_value :
2964
2974
onchange_hook = getattr (self , '_onchange_{}' .format (param ), None )
2965
2975
if onchange_hook is not None :
2966
- onchange_hook (old = current_value , new = value )
2976
+ onchange_hook (old = orig_value , new = new_value )
2967
2977
2968
2978
shell_parser = ACArgumentParser ()
2969
2979
setattr (shell_parser .add_argument ('command' , help = 'the command to run' ),
0 commit comments