def check_class():
"""
Return the class name for the current frame.
If the result is ** None ** means that the call is made from a module.
"""
# get frames
frames = inspect.stack()
cls = None
# should be the third frame
# 0: this function
# 1: function/decorator
# 2: class that contains the function
if len(frames) > 2:
frame = frames[2][0]
if '__module__' in frame.f_code.co_names:
cls = SillyClass(**frame.f_locals)
cls.__cls_name__ = frame.f_code.co_name
return cls
评论列表
文章目录