// default_value if provided (or the item"s actual default value if not) and
// logged as "missing".
lc_variables = {k.lower(): v for k, v in list(variables.items())}
for valid_lc_name, metadata in list(valid_lc_variables.items()):
if valid_lc_name not in lc_variables:
diff_log.append(("missing", metadata.name, None, None))
valid_variables[metadata.name] = default_value if \
After Change
def extract_valid_variables(self, variables, catalog, default_value=None):
valid_variables = {}
diff_log = OrderedDict([(k, []) for k in ("miscapitalized", "extra", "missing")])
lc_catalog = {k.lower(): v for k, v in catalog.items()}
// First check that the names of all variables are valid (i.e., listed
// in the official catalog). Invalid variables are logged as "extras".
// Variable names that are valid but differ in capitalization are still
// added to valid_variables but with the proper capitalization. They
// are also logged as "miscapitalized".
for var_name, var_value in variables.items():
if var_name in catalog:
valid_variables[var_name] = var_value
else:
lc_var_name = var_name.lower()
if lc_var_name in lc_catalog:
valid_name = lc_catalog[lc_var_name].name
diff_log["miscapitalized"].append((valid_name, var_name))
valid_variables[valid_name] = var_value
else:
diff_log["extra"].append(var_name)