MCPcopy Create free account
hub / github.com/nodejs/node / getitem

Method getitem

tools/inspector_protocol/jinja2/environment.py:408–423  ·  view source on GitHub ↗

Get an item or attribute of an object but prefer the item.

(self, obj, argument)

Source from the content-addressed store, hash-verified

406 key=lambda x: x.priority))
407
408 def getitem(self, obj, argument):
409 """Get an item or attribute of an object but prefer the item."""
410 try:
411 return obj[argument]
412 except (AttributeError, TypeError, LookupError):
413 if isinstance(argument, string_types):
414 try:
415 attr = str(argument)
416 except Exception:
417 pass
418 else:
419 try:
420 return getattr(obj, attr)
421 except AttributeError:
422 pass
423 return self.undefined(obj=obj, name=argument)
424
425 def getattr(self, obj, attribute):
426 """Get an item or attribute of an object but prefer the attribute.

Callers 2

attrgetterFunction · 0.45
as_constMethod · 0.45

Calls 1

strFunction · 0.85

Tested by

no test coverage detected