gluonts.util 模块#
- gluonts.util.copy_with(obj: gluonts.util.T, **kwargs) gluonts.util.T [source]#
返回 obj 的副本,并使用 kwargs 更新副本的属性。
@dataclass class MyClass: value: int a = MyClass(1) b = copy_with(a, value=2) assert a.value == 1 assert b.value == 2
- gluonts.util.lazy_property(method)[source]#
延迟评估的属性。
这与以下内容相同
@property @lru_cache(1) def my_property(self): ...
除了更简洁之外,lazy_property 在类型检查时可以像 property 一样工作,因此也支持 mypy。
此实现遵循 functools 文档中的方法,并模仿了 Python 3.8 中引入的 functools.cached_property。