Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions python/extractor/semmle/python/parser/tsg_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ def _decode_tsg_node_attributes(encoded_attrs, path, logger):
)
return attrs

def _format_node_attributes(attrs):
return repr(dict(sorted(attrs.items())))
Comment thread
tausbn marked this conversation as resolved.

def read_tsg_python_output(path, logger):
command_args = tsg_command + [path]
p = subprocess.Popen(command_args, stdout=subprocess.PIPE)
Expand Down Expand Up @@ -203,7 +206,11 @@ def get_context(id, node_attr, path, logger):

while "ctx" not in node_attr[id]:
if "_inherited_ctx" not in node_attr[id]:
logger.error("No context for node {} in file {} with attributes {}\n".format(id, path, node_attr[id]))
logger.error(
"No context for node {} in file {} with attributes {}\n".format(
id, path, _format_node_attributes(node_attr[id])
)
)
# A missing context is most likely to be a "load", so return that.
return ast.Load()
id = node_attr[id]["_inherited_ctx"].id
Expand Down Expand Up @@ -315,7 +322,11 @@ def parse(path, logger):
nodes[id] = attrs["_is_literal"]
continue
if "_kind" not in attrs:
logger.error("Error: Graph node {} with attributes {} has no `_kind`!\n".format(id, attrs))
logger.error(
"Error: Graph node {} with attributes {} has no `_kind`!\n".format(
id, _format_node_attributes(attrs)
)
)
continue
# This is not the node we are looking for (so don't bother creating it).
if "_skip_to" in attrs:
Expand Down Expand Up @@ -353,7 +364,7 @@ def parse(path, logger):
if field.startswith("_"): continue
if field == "ctx": continue
if field != "parenthesised" and field not in expected_fields:
logger.warning("Unknown field {} found among {} in node {}\n".format(field, attrs, id))
logger.warning("Unknown field {} found among {} in node {}\n".format(field, _format_node_attributes(attrs), id))

# For fields that point to other AST nodes.
if isinstance(val, Node):
Expand Down