ats_utilities.utils.reflection module¶
- Module
reflection.py
- Copyright
Copyright (C) 2017 - 2026 Vladimir Roncevic <elektron.ronca@gmail.com> ats_utilities is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. ats_utilities is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
- Info
Factory universally injects instances, gets private instances and setup instance string representation. Encapsulates core utilities to minimize constructor overhead. Provides a simple factory mechanism for dependency injection.
- ats_utilities.utils.reflection.cls_name(instance: Any) str[source]¶
Returns the class name of an instance.
- Parameters:
instance (<Any>) – The class instance.
- Returns:
The class name in string format.
- Return type:
<str>
- Exceptions:
None.
- ats_utilities.utils.reflection.get_pvt(instance: Any, attr_name: str) Any[source]¶
Dynamically retrieves a private attribute from an instance.
- Parameters:
instance (<Any>) – The class instance (self) containing the attribute.
attr_name (<str>) – The target private attribute name (e.g., ‘_checker’).
- Returns:
The resolved attribute value.
- Return type:
<Any>
- Exceptions:
- AttributeError: Attribute must start with ‘_’ prefix.
- ats_utilities.utils.reflection.has_attrs(*attr_names: str) Callable[[Callable[[...], Any]], Callable[[...], Any]][source]¶
Checks if instance attribute is defined and has value or not. In case attribute value is not defined set default value to None. In case attribute value is not defined and not empty, raise ATSValueError exception.
- Parameters:
attr_names (<tuple[str, ...]>) – Tuple of attribute names to check.
- Returns:
Decorated function.
- Return type:
<Callable[…, Any]>
- Exceptions:
- ATSValueError: Missing or empty attribute: ‘{attr}’.
- ats_utilities.utils.reflection.to_str(instance: Any) str[source]¶
Generates a standardized string representation for any class instance. Cleans private attributes and appends memory addresses in hex.
- Parameters:
instance (<Any>) – The class instance to format.
- Returns:
String representation of the instance.
- Return type:
<str>
- Exceptions:
None.