Copies attribute from module object to self. Raises if object not of expected class

        Args:
            module: module object
            varname: variable name
            cls: expected class of variable
            attrname: attribute name of self. Falls back to varname

def _copy_attr(self, module, varname, cls, attrname=None):
        """
        Copies attribute from module object to self. Raises if object not of expected class

        Args:
            module: module object
            varname: variable name
            cls: expected class of variable
            attrname: attribute name of self. Falls back to varname
        """

        if not hasattr(module, varname):
            raise RuntimeError("Variable '{}' not found".format(varname))

        obj = getattr(module, varname)

        if not isinstance(obj, cls):
            raise RuntimeError(
                "Expecting fobj to be a {}, not a '{}'".format(cls.__name__, obj.__class__.__name__))

        if attrname is None:
            attrname = varname

        setattr(self, attrname, obj)