# Buggy code
def get_class_members(
    subject: Any, objpath: List[str], attrgetter: Callable
) -> Dict[str, "ObjectMember"]:
    """Get members and attributes of target class."""
    from sphinx.ext.autodoc import INSTANCEATTR, ObjectMember

    # the members directly defined in the class
    obj_dict = attrgetter(subject, "__dict__", {})

    members = {}  # type: Dict[str, ObjectMember]

    # enum members
    if isenumclass(subject):
        for name, value in subject.__members__.items():
            if name not in members:
                members[name] = ObjectMember(name, value, class_=subject)

        superclass = subject.__mro__[1]
        for name in obj_dict:
            if name not in superclass.__dict__:
                value = safe_getattr(subject, name)
                members[name] = ObjectMember(name, value, class_=subject)

    # members in __slots__
    try:
        __slots__ = getslots(subject)
        if __slots__:
            from sphinx.ext.autodoc import SLOTSATTR

            for name, docstring in __slots__.items():
                members[name] = ObjectMember(
                    name, SLOTSATTR, class_=subject, docstring=docstring
                )
    except (AttributeError, TypeError, ValueError):
        pass

    # other members
    for name in dir(subject):
        try:
            value = attrgetter(subject, name)
            unmangled = unmangle(subject, name)
            if unmangled and unmangled not in members:
                if name in obj_dict:
                    members[unmangled] = ObjectMember(unmangled, value, class_=subject)
                else:
                    members[unmangled] = ObjectMember(unmangled, value)
        except AttributeError:
            continue

    try:
        for cls in getmro(subject):
            # annotation only member (ex. attr: int)
            try:
                for name in getannotations(cls):
                    name = unmangle(cls, name)
                    if name and name not in members:
                        members[name] = ObjectMember(name, INSTANCEATTR, class_=cls)
            except AttributeError:
                pass

            # append instance attributes (cf. self.attr1) if analyzer knows
            try:
                modname = safe_getattr(cls, "__module__")
                qualname = safe_getattr(cls, "__qualname__")
                analyzer = ModuleAnalyzer.for_module(modname)
                analyzer.analyze()
                for (ns, name), docstring in analyzer.attr_docs.items():
                    if ns == qualname and name not in members:
                        members[name] = ObjectMember(
                            name,
                            INSTANCEATTR,
                            class_=cls,
                            docstring="\n".join(docstring),
                        )
            except (AttributeError, PycodeError):
                pass
    except AttributeError:
        pass

    return members


# Traceback (TypeError)
WARNING: autodoc: failed to import module 'bar' from module 'foo'; the following exception was raised:
Traceback (most recent call last):
File "/home/andy/.local/share/virtualenvs/sphinx_decorator_bug-0V71t1Ku/lib/python3.7/site-packages/sphinx/ext/autodoc/importer.py", line 66, in import_module
return importlib.import_module(modname)
File "/home/andy/.local/share/virtualenvs/sphinx_decorator_bug-0V71t1Ku/lib64/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/opt/projects/sphinx_decorator_bug/foo/bar.py", line 29, in <module>
@mocked_module.decorator2(BaseClass)
TypeError: __init__() takes 1 positional argument but 2 were given

# Fixed code
def get_class_members(
    subject: Any, objpath: List[str], attrgetter: Callable
) -> Dict[str, "ObjectMember"]:
    """Get members and attributes of target class."""
    from sphinx.ext.autodoc import INSTANCEATTR, ObjectMember

    # the members directly defined in the class
    obj_dict = attrgetter(subject, "__dict__", {})

    members = {}  # type: Dict[str, ObjectMember]

    # enum members
    if isenumclass(subject):
        for name, value in subject.__members__.items():
            if name not in members:
                members[name] = ObjectMember(name, value, class_=subject)

        superclass = subject.__mro__[1]
        for name in obj_dict:
            if name not in superclass.__dict__:
                value = safe_getattr(subject, name)
                members[name] = ObjectMember(name, value, class_=subject)

    # members in __slots__
    try:
        __slots__ = getslots(subject)
        if __slots__:
            from sphinx.ext.autodoc import SLOTSATTR

            for name, docstring in __slots__.items():
                members[name] = ObjectMember(
                    name, SLOTSATTR, class_=subject, docstring=docstring
                )
    except (AttributeError, TypeError, ValueError):
        pass

    # other members
    for name in dir(subject):
        try:
            value = attrgetter(subject, name)
            if ismock(value):
                value = undecorate(value)

            unmangled = unmangle(subject, name)
            if unmangled and unmangled not in members:
                if name in obj_dict:
                    members[unmangled] = ObjectMember(unmangled, value, class_=subject)
                else:
                    members[unmangled] = ObjectMember(unmangled, value)
        except AttributeError:
            continue

    try:
        for cls in getmro(subject):
            # annotation only member (ex. attr: int)
            try:
                for name in getannotations(cls):
                    name = unmangle(cls, name)
                    if name and name not in members:
                        members[name] = ObjectMember(name, INSTANCEATTR, class_=cls)
            except AttributeError:
                pass

            # append instance attributes (cf. self.attr1) if analyzer knows
            try:
                modname = safe_getattr(cls, "__module__")
                qualname = safe_getattr(cls, "__qualname__")
                analyzer = ModuleAnalyzer.for_module(modname)
                analyzer.analyze()
                for (ns, name), docstring in analyzer.attr_docs.items():
                    if ns == qualname and name not in members:
                        members[name] = ObjectMember(
                            name,
                            INSTANCEATTR,
                            class_=cls,
                            docstring="\n".join(docstring),
                        )
            except (AttributeError, PycodeError):
                pass
    except AttributeError:
        pass

    return members