|
49 | 49 | # Module-level configuration |
50 | 50 | # --------------------------------------------------------------------------- |
51 | 51 |
|
52 | | -# Controls where ``LazyModule.__setattr__`` writes non-internal |
53 | | -# attributes when the real module has not yet been loaded (or when |
54 | | -# loading has failed). |
55 | | -# |
56 | | -# Accepted values: |
57 | | -# * ``"module"`` (default, backward-compatible): the attribute is |
58 | | -# forwarded to the underlying module via ``setattr(real, ...)``. |
59 | | -# This means a value written through the proxy becomes visible |
60 | | -# globally (because Python modules are singletons in |
61 | | -# ``sys.modules``). This matches the behaviour of ordinary |
62 | | -# ``import foo`` followed by ``foo.bar = ...``. |
63 | | -# * ``"proxy"``: the attribute is mounted on the proxy shell via |
64 | | -# ``object.__setattr__(self, ...)``. The underlying module is |
65 | | -# **not** loaded as a side effect, and the value is visible only |
66 | | -# through this proxy instance. Use this when you want to attach |
67 | | -# scratch state to a lazy module without paying for the import |
68 | | -# or polluting the real module's namespace. |
69 | | -# |
70 | | -# Why a global instead of a per-instance flag? The two modes are |
71 | | -# not usually mixed in the same project; a single global keeps the |
72 | | -# API surface small. Change at your own risk and reset it before any |
73 | | -# code that expects the default behaviour runs. |
| 52 | + |
74 | 53 | SETATTR_TARGET = "module" |
| 54 | +""" |
| 55 | +Controls where ``LazyModule.__setattr__`` writes non-internal |
| 56 | +attributes when the real module has not yet been loaded (or when |
| 57 | +loading has failed). |
| 58 | +
|
| 59 | +Accepted values: |
| 60 | + * ``"module"`` (default, backward-compatible): the attribute is |
| 61 | + forwarded to the underlying module via ``setattr(real, ...)``. |
| 62 | + This means a value written through the proxy becomes visible |
| 63 | + globally (because Python modules are singletons in |
| 64 | + ``sys.modules``). This matches the behaviour of ordinary |
| 65 | + ``import foo`` followed by ``foo.bar = ...``. |
| 66 | + * ``"proxy"``: the attribute is mounted on the proxy shell via |
| 67 | + ``object.__setattr__(self, ...)``. The underlying module is |
| 68 | + **not** loaded as a side effect, and the value is visible only |
| 69 | + through this proxy instance. Use this when you want to attach |
| 70 | + scratch state to a lazy module without paying for the import |
| 71 | + or polluting the real module's namespace. |
| 72 | +
|
| 73 | +Why a global instead of a per-instance flag? The two modes are |
| 74 | +not usually mixed in the same project; a single global keeps the |
| 75 | +API surface small. Change at your own risk and reset it before any |
| 76 | +code that expects the default behaviour runs.""" |
75 | 77 |
|
76 | 78 | # GNUv3 License, add in <2018>, by <Evan Yang> |
77 | 79 | class LazyModule(types.ModuleType): |
|
0 commit comments