Factory class in Python with a mapping dictionary returns TypeError
As the error message says, instances of classmethod are not callable. When you call a class method with something like CreateCaseFactory.create(...), the descriptor protocol "extracts" the underlying function from the class method and calls it with CreateCaseFactory as the first argument.
create_case_1 and _create_case_2 should not be class methods, but regular functions.
class CreateCaseFactory:
    @classmethod
    def create(cls, user_id: uuid.UUID, type_: str) -> str:
        creator = cls.CASE_TO_METHOD_MAP.get(type_)
        if creator:
            return creator(cls, user_id)
        else:
            raise Exception("Invalid type")

    def _create_case_1(cls, user_id: uuid.UUID) -> str:
        result = f"Dummy Use Case 1 created for user {user_id}"
        return result

    def _create_case_2(cls, user_id: uuid.UUID) -> str:
        result = f"Dummy Use Case 2 created for user {user_id}"
        return result

    CASE_TO_METHOD_MAP = {
        "case_1": _create_case_1,
        "case_2": _create_case_2,
    }


I made something like this dummy class:
class CreateCaseFactory:
    @classmethod
    def create(cls, user_id: uuid.UUID, type_: str) -> str:
        creator = cls.CASE_TO_METHOD_MAP.get(type_)
        if creator:
            return creator(user_id)
        else:
            raise Exception("Invalid type")

    @classmethod
    def _create_case_1(cls, user_id: uuid.UUID) -> str:
        result = f"Dummy Use Case 1 created for user {user_id}"
        return result

    @classmethod
    def _create_case_2(cls, user_id: uuid.UUID) -> str:
        result = f"Dummy Use Case 2 created for user {user_id}"
        return result

    CASE_TO_METHOD_MAP = {
        "case_1": _create_case_1,
        "case_2": _create_case_2,
    }

but I get an error when I try to run it:
        if creator:
>           return creator(user_id)
E           TypeError: 'classmethod' object is not callable

How can I make this factory class work.
