def find_dict_index(dict_node, key):
"""Given a key, find the index of the corresponding dict entry."""
assert dict_node.__class__ is ast.Dict, ast_err_msg(dict_node)
indices = [i for i, n in enumerate(dict_node.keys) if
n.__class__ is ast.Str and n.s == key]
assert len(indices) < 2, (
'Found redundant dict entries for key "%s"' % key)
return indices[0] if indices else None
评论列表
文章目录