Get an item or attribute of an object but prefer the item.
(
self, obj: t.Any, argument: t.Union[str, t.Any]
)
| 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. |
no test coverage detected