<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def ast_from_class(self, klass, modname=None):
 """get astroid for the given class"""

        if modname is None:
            try:
                modname = klass.__module__
            except AttributeError as exc:
                raise exceptions.AstroidBuildingError(
                    "Unable to get module for class {class_name}.",
                    cls=klass,
                    class_repr=safe_repr(klass),
                    modname=modname,
                ) from exc
        modastroid = self.ast_from_module_name(modname)
        return modastroid.getattr(klass.__name__)[0]