Skip to content

Commit b2c6c1e

Browse files
committed
Add warnings for SETATTR_TARGET
1 parent ddd7c54 commit b2c6c1e

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

‎docs/documentation.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,11 @@ You should rarely need to instantiate `LazyModule` directly — use
208208
| `SUPPORT_LAZY_IMPORT` | `bool` | Always `True` — this package provides its own implementation. |
209209
| `SETATTR_TARGET` | `Literal["module", "proxy"]` | Controls where ``LazyModule.__setattr__`` writes non-internal attributes when the real module has not yet been loaded (or when loading has failed). |
210210

211+
> [!WARNING] When `LAZY_SETATTR_TARGET = "proxy"`, attributes assigned directly to the proxy will
212+
> shadow attributes from the underlying module after the module is loaded. Use `"proxy"` only
213+
> when attaching transient metadata to proxies; prefer `"module"` for regular application code to
214+
> avoid subtle naming-shadowing bugs.
215+
211216
---
212217

213218
## How it works

‎lazyimports/core.py‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
]
3333

3434

35+
# ---------------------------------------------------------------------------
36+
# Module-level configuration
37+
# ---------------------------------------------------------------------------
38+
3539
# License MIT <aiwonderland> in <2026>
3640

3741
# Native `lazy import` statement is available on Python 3.15+.
@@ -45,11 +49,9 @@
4549

4650
# License MIT <aiwonderland> in <2026>
4751

48-
# ---------------------------------------------------------------------------
49-
# Module-level configuration
50-
# ---------------------------------------------------------------------------
51-
52-
52+
# WARNING: When LAZY_SETATTR_TARGET = "proxy", attributes stored on the proxy
53+
# shadow identically named attributes from the real module once loaded.
54+
# Use "proxy" only for temporary proxy-local metadata.
5355
SETATTR_TARGET = "module"
5456
"""
5557
Controls where ``LazyModule.__setattr__`` writes non-internal

0 commit comments

Comments
 (0)