Get the readable name of a component. Args: component: The component to get the name of. Returns: The readable name of the component.
(
component: Component | ComponentCallable,
)
| 787 | |
| 788 | |
| 789 | def readable_name_from_component( |
| 790 | component: Component | ComponentCallable, |
| 791 | ) -> str | None: |
| 792 | """Get the readable name of a component. |
| 793 | |
| 794 | Args: |
| 795 | component: The component to get the name of. |
| 796 | |
| 797 | Returns: |
| 798 | The readable name of the component. |
| 799 | """ |
| 800 | if isinstance(component, Component): |
| 801 | return type(component).__name__ |
| 802 | if isinstance(component, (Var, int, float, str)): |
| 803 | return str(component) |
| 804 | if isinstance(component, Sequence): |
| 805 | return ", ".join(str(c) for c in component) |
| 806 | if callable(component): |
| 807 | module_name = getattr(component, "__module__", None) |
| 808 | if module_name is not None: |
| 809 | module = getmodule(component) |
| 810 | if module is not None: |
| 811 | module_name = module.__name__ |
| 812 | if module_name is not None: |
| 813 | return f"{module_name}.{component.__name__}" |
| 814 | return component.__name__ |
| 815 | return None |
| 816 | |
| 817 | |
| 818 | def _modify_exception(e: Exception) -> None: |