Skip to content

Commit 6d16910

Browse files
committed
feat: lazy load register_shutil
1 parent 33780f9 commit 6d16910

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ adheres to [Semantic Versioning](https://semver.org/).
77

88
## Unreleased
99

10+
### :rocket: Added
11+
12+
- Shorten import time by lazy loading the `register_shutil` function
13+
1014
### :bug: Fixes
1115

1216
- Fix assertion on Python 3.13 when build with `DEBUG`

src/python/backports/zstd/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131

3232
import backports.zstd._zstd as _zstd
3333
import enum
34-
from backports.zstd._shutil import register_shutil
3534
from backports.zstd._zstd import (ZstdCompressor, ZstdDecompressor, ZstdDict, ZstdError,
3635
get_frame_size, zstd_version)
3736
from backports.zstd._zstdfile import ZstdFile, open, _nbytes
@@ -247,3 +246,11 @@ class Strategy(enum.IntEnum):
247246

248247
# Check validity of the CompressionParameter & DecompressionParameter types
249248
_zstd.set_parameter_types(CompressionParameter, DecompressionParameter)
249+
250+
251+
# Lazy loading
252+
def __getattr__(name):
253+
if name == "register_shutil":
254+
from backports.zstd._shutil import register_shutil
255+
return register_shutil
256+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")

0 commit comments

Comments
 (0)