Return the nearest .entity_namespace for the given entity. If not immediately available, does an iterate to find a sub-element that has one, if any.
(
entity: Union[_HasEntityNamespace, ExternallyTraversible],
)
| 2585 | |
| 2586 | |
| 2587 | def _entity_namespace( |
| 2588 | entity: Union[_HasEntityNamespace, ExternallyTraversible], |
| 2589 | ) -> _EntityNamespace: |
| 2590 | """Return the nearest .entity_namespace for the given entity. |
| 2591 | |
| 2592 | If not immediately available, does an iterate to find a sub-element |
| 2593 | that has one, if any. |
| 2594 | |
| 2595 | """ |
| 2596 | try: |
| 2597 | return cast(_HasEntityNamespace, entity).entity_namespace |
| 2598 | except AttributeError: |
| 2599 | for elem in visitors.iterate(cast(ExternallyTraversible, entity)): |
| 2600 | if _is_has_entity_namespace(elem): |
| 2601 | return elem.entity_namespace |
| 2602 | else: |
| 2603 | raise |
| 2604 | |
| 2605 | |
| 2606 | @overload |
no test coverage detected