gluonts.util module#

gluonts.util.copy_with(obj: gluonts.util.T, **kwargs) gluonts.util.T[source]#

Return copy of obj and update attributes of the copy using 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 that is lazily evaluated.

This is the same as:

@property
@lru_cache(1)
def my_property(self):
    ...

In addition to be more concise, lazy_property also works with mypy, since it poses to be just property when type checked.

This implementation follows the recipe from the functools documentation, and mimics functools.cached_property which was introduced in Python 3.8.

gluonts.util.safe_extractall(tar: tarfile.TarFile, path: pathlib.Path = PosixPath('.'), members=None, *, numeric_owner=False)[source]#

Safe wrapper around TarFile.extractall that checks all destination files to be strictly within the given path.

gluonts.util.will_extractall_into(tar: tarfile.TarFile, path: pathlib.Path) None[source]#

Check that the content of tar will be extracted within path upon calling extractall.

Raise a PermissionError if not.