MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / QnResolver

Class QnResolver

tensorflow/python/autograph/pyct/qual_names.py:219–257  ·  view source on GitHub ↗

Annotates nodes with QN information. Note: Not using NodeAnnos to avoid circular dependencies.

Source from the content-addressed store, hash-verified

217
218
219class QnResolver(gast.NodeTransformer):
220 """Annotates nodes with QN information.
221
222 Note: Not using NodeAnnos to avoid circular dependencies.
223 """
224
225 def visit_Name(self, node):
226 node = self.generic_visit(node)
227 anno.setanno(node, anno.Basic.QN, QN(node.id))
228 return node
229
230 def visit_Attribute(self, node):
231 node = self.generic_visit(node)
232 if anno.hasanno(node.value, anno.Basic.QN):
233 anno.setanno(node, anno.Basic.QN,
234 QN(anno.getanno(node.value, anno.Basic.QN), attr=node.attr))
235 return node
236
237 def visit_Subscript(self, node):
238 # TODO(mdan): This may no longer apply if we overload getitem.
239 node = self.generic_visit(node)
240 s = node.slice
241 if not isinstance(s, gast.Index):
242 # TODO(mdan): Support range and multi-dimensional indices.
243 # Continuing silently because some demos use these.
244 return node
245 if isinstance(s.value, gast.Constant):
246 subscript = QN(NumberLiteral(s.value.value))
247 else:
248 # The index may be an expression, case in which a name doesn't make sense.
249 if anno.hasanno(node.slice.value, anno.Basic.QN):
250 subscript = anno.getanno(node.slice.value, anno.Basic.QN)
251 else:
252 return node
253 if anno.hasanno(node.value, anno.Basic.QN):
254 anno.setanno(node, anno.Basic.QN,
255 QN(anno.getanno(node.value, anno.Basic.QN),
256 subscript=subscript))
257 return node
258
259
260def resolve(node):

Callers 1

resolveFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected