MCPcopy Index your code
hub / github.com/datacamp/pythonwhat / _getx

Method _getx

pythonwhat/State.py:296–315  ·  view source on GitHub ↗

getter for Parser outputs

(self, Parser, ext_attr, tree)

Source from the content-addressed store, hash-verified

294
295 # add methods for retrieving parser outputs --------------------------
296 def _getx(self, Parser, ext_attr, tree):
297 """getter for Parser outputs"""
298 # return cached output if possible
299 cache_key = Parser.__name__ + str(hash(tree))
300 if self._parser_cache.get(cache_key):
301 p = self._parser_cache[cache_key]
302 else:
303 # otherwise, run parser over tree
304 p = Parser()
305 # set mappings for parsers that inspect attribute access
306 if ext_attr != "mappings" and Parser in [
307 FunctionParser,
308 ObjectAccessParser,
309 ]:
310 p.mappings = self.context_mappings.copy()
311 # run parser
312 p.visit(tree)
313 # cache
314 self._parser_cache[cache_key] = p
315 return getattr(p, ext_attr)
316
317
318# put a function on the dispatcher

Callers 1

__init__Method · 0.95

Calls 2

ParserClass · 0.85
copyMethod · 0.80

Tested by

no test coverage detected