我assert False在flask/helpers.py中的以下类的__init__方法中添加了一条语句:class locked_cached_property(object): """A decorator that converts a function into a lazy property. The function wrapped is called the first time to retrieve the result and then that calculated result is used the next time you access the value. Works like the one in Werkzeug but has a lock for thread safety. """ def __init__(self, func, name=None, doc=None): assert False # ^ this is the problem self.__name__ = name or func.__name__ self.__module__ = func.__module__ self.__doc__ = doc or func.__doc__ self.func = func self.lock = RLock() def __get__(self, obj, type=None): if obj is None: return self with self.lock: value = obj.__dict__.get(self.__name__, _missing) if value is _missing: value = self.func(obj) obj.__dict__[self.__name__] = value return value我很好奇一个assert False语句在__init__函数中是如何导致导入失败的。如果assert False是在__get__函数中,我仍然可以导入模块。这发生在 pytest 3.8.1 和 4.0.2 上。这是否意味着__init__在导入模块期间调用了装饰器?
添加回答
举报
0/150
提交
取消