@@ -39,8 +39,8 @@ def import_data(json_dir=JSON_DIR, json_fmatch=JSON_FNMATCH):
39
39
errors .append (
40
40
"Problem reading file {}," .format (json_file ) +
41
41
" reason: {}" .format (err ))
42
- if type (candidates ) != list :
43
- if type (candidates ) == OrderedDict :
42
+ if type (candidates ) is not list :
43
+ if type (candidates ) is OrderedDict :
44
44
data .append (candidates )
45
45
else :
46
46
errors .append (
@@ -56,13 +56,13 @@ def match_primitive_values(item_value, where_value):
56
56
"""Perform any odd logic on item matching.
57
57
"""
58
58
# Matching interpolation for keyboard constrained input.
59
- if type (item_value ) == str :
59
+ if type (item_value ) is str :
60
60
# Direct match
61
61
return bool (re .match (where_value , item_value ))
62
- elif type (item_value ) == int or type (item_value ) == float :
62
+ elif type (item_value ) is int or type (item_value ) is float :
63
63
# match after string conversion
64
64
return bool (re .match (where_value , str (item_value )))
65
- elif type (item_value ) == bool :
65
+ elif type (item_value ) is bool :
66
66
# help conversion to JSON booleans from the commandline
67
67
return bool (re .match (where_value , str (item_value ).lower ()))
68
68
else :
@@ -86,14 +86,14 @@ def matches_where(item, where_key, where_value):
86
86
# So we have some value.
87
87
item_value = item [where_key ]
88
88
# Matching interpolation for keyboard constrained input.
89
- if type (item_value ) == list :
89
+ if type (item_value ) is list :
90
90
# 1 level deep.
91
91
for next_level in item_value :
92
92
if match_primitive_values (next_level , where_value ):
93
93
return True
94
94
# else...
95
95
return False
96
- elif type (item_value ) == dict :
96
+ elif type (item_value ) is dict :
97
97
# Match against the keys of the dictionary... I question my logic.
98
98
# 1 level deep.
99
99
for next_level in item_value :
@@ -179,14 +179,14 @@ def key_counter(data, where_fn_list):
179
179
180
180
val = item [key ]
181
181
# If value is an object, tally key.subkey for all object subkeys
182
- if type (val ) == OrderedDict :
182
+ if type (val ) is OrderedDict :
183
183
for subkey in val .keys ():
184
184
if not subkey .startswith ('//' ):
185
185
stats [key + '.' + subkey ] += 1
186
186
187
187
# If value is a list of objects, tally key.subkey for each
188
- elif type (val ) == list :
189
- if all (type (e ) == OrderedDict for e in val ):
188
+ elif type (val ) is list :
189
+ if all (type (e ) is OrderedDict for e in val ):
190
190
for obj in val :
191
191
for subkey in obj .keys ():
192
192
if not subkey .startswith ('//' ):
@@ -208,13 +208,13 @@ def item_value_counter(_value):
208
208
if isinstance (_value , str ):
209
209
stats [_value ] += 1
210
210
# Cast numbers to strings
211
- elif type (_value ) == int or type (_value ) == float :
211
+ elif type (_value ) is int or type (_value ) is float :
212
212
stats [str (_value )] += 1
213
213
# Pull all values from objects
214
- elif type (_value ) == OrderedDict :
214
+ elif type (_value ) is OrderedDict :
215
215
stats += list_value_counter (list (_value .values ()))
216
216
# Pull values from list of objects or strings
217
- elif type (_value ) == list :
217
+ elif type (_value ) is list :
218
218
stats += list_value_counter (_value )
219
219
else :
220
220
raise ValueError ("Value '%s' has unknown type %s" %
@@ -267,14 +267,14 @@ def value_counter(data, search_key, where_fn_list):
267
267
268
268
# If this value is a list of objects, pull parent_key.child_key
269
269
# values from all of them to include in stats
270
- if type (parent_val ) == list and all (type (e ) == OrderedDict
270
+ if type (parent_val ) is list and all (type (e ) is OrderedDict
271
271
for e in parent_val ):
272
272
for od in parent_val :
273
273
if child_key in od :
274
274
stat_vals .append (od [child_key ])
275
275
276
276
# If this value is a single object, get value at parent_key.child_key
277
- elif type (parent_val ) == OrderedDict and child_key in parent_val :
277
+ elif type (parent_val ) is OrderedDict and child_key in parent_val :
278
278
stat_vals .append (parent_val [child_key ])
279
279
280
280
# Other kinds of data cannot be indexed by parent_key.child_key
@@ -381,7 +381,7 @@ def dumps(self):
381
381
while items :
382
382
k , v = items .pop (0 )
383
383
# Special cases first.
384
- if (k == "tools" or k == "components" ) and type (v ) == list :
384
+ if (k == "tools" or k == "components" ) and type (v ) is list :
385
385
self .list_of_lists (k , v )
386
386
else :
387
387
self .write_primitive_key_val (k , v )
0 commit comments