Skip to content

Commit

Permalink
add MetaNotAllowInstance (acheong08#1210)
Browse files Browse the repository at this point in the history
  • Loading branch information
CoolPlayLin authored Mar 24, 2023
1 parent d705a4d commit 9ae8a8e
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/revChatGPT/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from abc import ABCMeta, abstractmethod
from os import getenv

Any = object()

SUPPORT = [int(each) for each in python_version_tuple()][0] >= 3 and [int(each) for each in python_version_tuple()][1] >= 11
del python_version_tuple

Expand All @@ -18,6 +20,14 @@ def __init__(self, *args: object) -> None:
super().add_note("Project URL: https://github.com/acheong08/ChatGPT")
super().__init__(*args)

class MetaNotAllowInstance(type):
"""
Metaclasses that do not allow classes to be instantiated
"""
def __call__(self, *args: Any, **kwds: Any) -> Any:
error = ChatbotError("This class is not allowed to be instantiated")
raise error

class CommandError(ChatbotError):
pass

Expand Down Expand Up @@ -69,7 +79,7 @@ class OpenAIError(APIConnectionError):
class RequestError(APIConnectionError):
pass

class ErrorType:
class ErrorType(metaclass=MetaNotAllowInstance):
# define consts for the error codes
USER_ERROR = -1
UNKNOWN_ERROR = 0
Expand Down

0 comments on commit 9ae8a8e

Please sign in to comment.