File size: 1,533 Bytes
f5776d3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
from .modules import *
from .primitives import *
from .templates import *
from .utils import settings
"""
TODO:
The DspModule class serves as a proxy to our original 'dsp' module. It provides direct access to settings
stored in `dsp_settings` as if they were top-level attributes of the 'dsp' module, while also ensuring that
all other regular attributes (like functions, classes, or submodules) of the 'dsp' module remain accessible.
By replacing the module's symbols with an instance of DspModule, we allow users to access settings
with the syntax `dsp.<setting_name>` instead of the longer `dsp.dsp_settings.<setting_name>`. This makes
for more concise and intuitive code. However, due to its unconventional nature, developers should be
careful when modifying this module to ensure they maintain the expected behavior and access patterns.
"""
"""
class DspModule:
def __init__(self):
# Import and store the original module object
self._original_module = sys.modules[__name__]
def __getattr__(self, name):
# First, try getting the attribute from the original module
if hasattr(self._original_module, name):
return getattr(self._original_module, name)
# Next, check dsp_settings
if hasattr(dsp_settings, name):
return getattr(dsp_settings, name)
raise AttributeError(f"'{type(self).__name__}' object and the original module have no attribute '{name}'")
import sys
sys.modules[__name__] = DspModule()
""" |