@@ -270,7 +270,7 @@ def _check_write_command_response(results):
270
270
271
271
272
272
def _fields_list_to_dict (fields , option_name ):
273
- """Takes a list of field names and returns a matching dictionary.
273
+ """Takes a sequence of field names and returns a matching dictionary.
274
274
275
275
["a", "b"] becomes {"a": 1, "b": 1}
276
276
@@ -280,15 +280,13 @@ def _fields_list_to_dict(fields, option_name):
280
280
"""
281
281
if isinstance (fields , collections .Mapping ):
282
282
return fields
283
- elif isinstance (fields , list ):
284
- as_dict = {}
285
- for field in fields :
286
- if not isinstance (field , string_type ):
287
- raise TypeError ("%s must be a list of key names, each an "
288
- "instance of %s" % (option_name ,
289
- string_type .__name__ ))
290
- as_dict [field ] = 1
291
- return as_dict
292
- else :
293
- raise TypeError ("%s must be a mapping or "
294
- "list of key names" % (option_name ,))
283
+
284
+ if isinstance (fields , collections .Sequence ):
285
+ if not all (isinstance (field , string_type ) for field in fields ):
286
+ raise TypeError ("%s must be a list of key names, each an "
287
+ "instance of %s" % (option_name ,
288
+ string_type .__name__ ))
289
+ return dict .fromkeys (fields , 1 )
290
+
291
+ raise TypeError ("%s must be a mapping or "
292
+ "list of key names" % (option_name ,))
0 commit comments