@@ -188,23 +188,26 @@ def _find_macro(self, name):
188
188
return None
189
189
190
190
def _check_macro_definitions (self , definitions ):
191
- """Ensures that every element of 'definitions' is a valid macro
192
- definition, ie. either (name,value) 2-tuple or a (name,) tuple. Do
193
- nothing if all definitions are OK, raise TypeError otherwise.
194
- """
191
+ """Ensure that every element of 'definitions' is valid."""
195
192
for defn in definitions :
196
- if not (
197
- isinstance (defn , tuple )
198
- and (
199
- len (defn ) in (1 , 2 )
200
- and (isinstance (defn [1 ], str ) or defn [1 ] is None )
201
- )
202
- and isinstance (defn [0 ], str )
203
- ):
204
- raise TypeError (
205
- f"invalid macro definition '{ defn } ': "
206
- "must be tuple (string,), (string, string), or (string, None)"
207
- )
193
+ self ._check_macro_definition (defn )
194
+
195
+ def _check_macro_definition (self , defn ):
196
+ """
197
+ Raise a TypeError if defn is not valid.
198
+
199
+ A valid definition is either a (name, value) 2-tuple or a (name,) tuple.
200
+ """
201
+ valid = (
202
+ isinstance (defn , tuple )
203
+ and (len (defn ) in (1 , 2 ) and (isinstance (defn [1 ], str ) or defn [1 ] is None ))
204
+ and isinstance (defn [0 ], str )
205
+ )
206
+ if not valid :
207
+ raise TypeError (
208
+ f"invalid macro definition '{ defn } ': "
209
+ "must be tuple (string,), (string, string), or (string, None)"
210
+ )
208
211
209
212
# -- Bookkeeping methods -------------------------------------------
210
213
0 commit comments