##// END OF EJS Templates
Fix %autocall doesn't handle integer parsing errors
Lightyagami1 -
Show More
@@ -104,16 +104,32 b' class AutoMagics(Magics):'
104 # all-random (note for auto-testing)
104 # all-random (note for auto-testing)
105 """
105 """
106
106
107 valid_modes = {
108 0: "Off",
109 1: "Smart",
110 2: "Full",
111 }
112
113 def errorMessage() -> str:
114 error = "Valid modes: "
115 for k, v in valid_modes.items():
116 error += str(k) + "->" + v + ", "
117 error = error[:-2] # remove tailing `, ` after last element
118 return error
119
107 if parameter_s:
120 if parameter_s:
121 if not parameter_s in map(str, valid_modes.keys()):
122 error(errorMessage())
123 return
108 arg = int(parameter_s)
124 arg = int(parameter_s)
109 else:
125 else:
110 arg = 'toggle'
126 arg = 'toggle'
111
127
112 if not arg in (0, 1, 2, 'toggle'):
128 if not arg in (*list(valid_modes.keys()), "toggle"):
113 error('Valid modes: (0->Off, 1->Smart, 2->Full')
129 error(errorMessage())
114 return
130 return
115
131
116 if arg in (0, 1, 2):
132 if arg in (valid_modes.keys()):
117 self.shell.autocall = arg
133 self.shell.autocall = arg
118 else: # toggle
134 else: # toggle
119 if self.shell.autocall:
135 if self.shell.autocall:
@@ -125,4 +141,4 b' class AutoMagics(Magics):'
125 except AttributeError:
141 except AttributeError:
126 self.shell.autocall = self._magic_state.autocall_save = 1
142 self.shell.autocall = self._magic_state.autocall_save = 1
127
143
128 print("Automatic calling is:",['OFF','Smart','Full'][self.shell.autocall])
144 print("Automatic calling is:", list(valid_modes.values())[self.shell.autocall])
General Comments 0
You need to be logged in to leave comments. Login now