polymerist.genutils.attrs

For dynamically inspecting and modifying attributes of Python objects

Functions

compile_argfree_getable_attrs(→ dict[str, Any])

Compile the values of all methods of an object which require no arguments other than perhaps the object itself (this EXCLUDES properties)

Module Contents

polymerist.genutils.attrs.compile_argfree_getable_attrs(obj: Any, getter_re: str | re.Pattern = '.*', repl_str: str | None = None) dict[str, Any][source]

Compile the values of all methods of an object which require no arguments other than perhaps the object itself (this EXCLUDES properties) Returns a dict whose keys are the names of the methods called and whose values are the return values of those object methods

Can optionally filter the names of returned method using a regular expression, passed to “getter_re” Can also optionally replace the chosen regex with an arbitrary string (including the empty string), passed to “repl_str”

Parameters:
  • obj (Any) – Any object instance

  • getter_re (str or re.Pattern (optional), default “.*) – Optional regular expression to use for filtering down returned methods Only methods whose names match the target regex are returns

  • repl_str (str (optional)) – If provided, will replace the for example, repl_str=”” can be used to delete the regex from returned method names

Returns:

getable_dict – dict whose keys are the selected method names and whose values are the corresponding method returns

Return type:

dict[str, Any]