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

Method getitem

deps/v8/third_party/jinja2/environment.py:461–478  ·  view source on GitHub ↗

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

(
        self, obj: t.Any, argument: t.Union[str, t.Any]
    )

Source from the content-addressed store, hash-verified

459 return iter(sorted(self.extensions.values(), key=lambda x: x.priority))
460
461 def getitem(
462 self, obj: t.Any, argument: t.Union[str, t.Any]
463 ) -> t.Union[t.Any, Undefined]:
464 """Get an item or attribute of an object but prefer the item."""
465 try:
466 return obj[argument]
467 except (AttributeError, TypeError, LookupError):
468 if isinstance(argument, str):
469 try:
470 attr = str(argument)
471 except Exception:
472 pass
473 else:
474 try:
475 return getattr(obj, attr)
476 except AttributeError:
477 pass
478 return self.undefined(obj=obj, name=argument)
479
480 def getattr(self, obj: t.Any, attribute: str) -> t.Any:
481 """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