Get an item or attribute of an object but prefer the attribute. Unlike :meth:`getitem` the attribute *must* be a string.
(self, obj: t.Any, attribute: str)
| 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. |
| 482 | Unlike :meth:`getitem` the attribute *must* be a string. |
| 483 | """ |
| 484 | try: |
| 485 | return getattr(obj, attribute) |
| 486 | except AttributeError: |
| 487 | pass |
| 488 | try: |
| 489 | return obj[attribute] |
| 490 | except (TypeError, LookupError, AttributeError): |
| 491 | return self.undefined(obj=obj, name=attribute) |
| 492 | |
| 493 | def _filter_test_common( |
| 494 | self, |
no outgoing calls
no test coverage detected