在工作中,我遇到了这种方法,它困扰着我。事实上,方法的名称、文档和实现并没有真正相互匹配(并且传递 true 使 true 的条件变为 false),我不明白拥有这样一个方法的意义(这是生产代码):
# @brief An utility method that raises if the singleton is not in a good
# state
#@param expect_instanciated bool : if True we expect that the class is
# allready instanciated, else not
# @throw RuntimeError
@classmethod
def singleton_assert(cls, expect_instanciated=False):
if expect_instanciated:
if not cls.started():
raise RuntimeError("The Settings class is not started yet")
else:
if cls.started():
raise RuntimeError("The Settings class is already started")
Run Code Online (Sandbox Code Playgroud)
以下是我的担忧: