@@ -100,54 +100,29 @@ def _get_option(pat, silent=False):
100
100
return root [k ]
101
101
102
102
103
- def _set_single_option (pat , value , silent ):
104
- key = _get_single_key (pat , silent )
105
-
106
- o = _get_registered_option (key )
107
- if o and o .validator :
108
- o .validator (value )
109
-
110
- # walk the nested dict
111
- root , k = _get_root (key )
112
- root [k ] = value
113
-
114
- if o .cb :
115
- o .cb (key )
116
-
117
-
118
- def _set_multiple_options (args , silent ):
119
- for k , v in zip (args [::2 ], args [1 ::2 ]):
120
- _set_single_option (k , v , silent )
121
-
122
-
123
103
def _set_option (* args , ** kwargs ):
124
104
# must at least 1 arg deal with constraints later
125
105
nargs = len (args )
126
106
if not nargs or nargs % 2 != 0 :
127
107
raise ValueError ("Must provide an even number of non-keyword "
128
108
"arguments" )
129
109
130
- # must be 0 or 1 kwargs
131
- nkwargs = len (kwargs )
132
- if nkwargs not in (0 , 1 ):
133
- raise ValueError ("The can only be 0 or 1 keyword arguments" )
110
+ # default to false
111
+ silent = kwargs .get ('silent' , False )
134
112
135
- # if 1 kwarg then it must be silent=True or silent=False
136
- if nkwargs :
137
- k , = list (kwargs .keys ())
138
- v , = list (kwargs .values ())
113
+ for k , v in zip (args [::2 ], args [1 ::2 ]):
114
+ key = _get_single_key (k , silent )
139
115
140
- if k != 'silent' :
141
- raise ValueError ("the only allowed keyword argument is 'silent', "
142
- "you passed '{0}'" .format (k ))
143
- if not isinstance (v , bool ):
144
- raise TypeError ("the type of the keyword argument passed must be "
145
- "bool, you passed a {0}" .format (v .__class__ ))
116
+ o = _get_registered_option (key )
117
+ if o and o .validator :
118
+ o .validator (v )
146
119
147
- # default to false
148
- silent = kwargs . get ( 'silent' , False )
149
- _set_multiple_options ( args , silent )
120
+ # walk the nested dict
121
+ root , k = _get_root ( key )
122
+ root [ k ] = v
150
123
124
+ if o .cb :
125
+ o .cb (key )
151
126
152
127
def _describe_option (pat = '' , _print_desc = True ):
153
128
0 commit comments