UniCoreFW

property_func()

Return a function that retrieves a property value by name.

Implementation

Args: prop_name: The property name to retrieve Returns: A function that gets the property from objects

Example

obj = {'a': 1, 'b': 2} property_func('a')(obj)

Expected output: 1

Source Code

def property_func(prop_name: str) -> Callable: return ( lambda obj: obj.get(prop_name) if isinstance(obj, dict) else getattr(obj, prop_name, None) )