当前位置: 首页>>代码示例>>Python>>正文


Python ModuleType.__setattr__方法代码示例

本文整理汇总了Python中types.ModuleType.__setattr__方法的典型用法代码示例。如果您正苦于以下问题:Python ModuleType.__setattr__方法的具体用法?Python ModuleType.__setattr__怎么用?Python ModuleType.__setattr__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在types.ModuleType的用法示例。


在下文中一共展示了ModuleType.__setattr__方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __strict__

# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __setattr__ [as 别名]
 def __strict__(self):
     ModuleType.__setattr__(self, "__class__", NormalModule)
     if "." in self.__name__:
         parent_name, leaf_name = self.__name__.rsplit(".", 1)
         parent = sys.modules[parent_name]
         setattr(parent, leaf_name, self) # this will __strict__ the parent
     reload(self)
开发者ID:pombreda,项目名称:nimp,代码行数:9,代码来源:lazy2.py

示例2: _make_submodule_autoimporter_module

# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __setattr__ [as 别名]
def _make_submodule_autoimporter_module(ipython, module):
    """
    Return a module sub-instance that automatically imports submodules.

    Implemented as a factory function to close over the real module.
    """

    if not hasattr(module, "__path__"):  # We only need to wrap packages.
        return module

    class SubmoduleAutoImporterModule(ModuleType):
        @property
        def __dict__(self):
            return module.__dict__

        # Overriding __setattr__ is needed even when __dict__ is overridden.
        def __setattr__(self, name, value):
            setattr(module, name, value)

        def __getattr__(self, name):
            try:
                value = getattr(module, name)
                if isinstance(value, ModuleType):
                    value = _make_submodule_autoimporter_module(ipython, value)
                return value
            except AttributeError:
                import_target = "{}.{}".format(self.__name__, name)
                try:
                    submodule = importlib.import_module(import_target)
                except getattr(builtins, "ModuleNotFoundError",
                               ImportError):  # Py<3.6.
                    pass
                else:
                    _report(ipython, "import {}".format(import_target))
                    return _make_submodule_autoimporter_module(
                        ipython, submodule)
                raise  # Raise AttributeError without chaining ImportError.

    sai_module = SubmoduleAutoImporterModule(module.__name__)
    # Apparently, `module?` does not trigger descriptors, so we need to
    # set the docstring explicitly (on the instance, not on the class).
    # Then then only difference in the output of `module?` becomes the type
    # (`SubmoduleAutoImportModule` instead of `module`), which we should keep
    # for clarity.
    ModuleType.__setattr__(sai_module, "__doc__", module.__doc__)
    return sai_module
开发者ID:anntzer,项目名称:ipython-autoimport,代码行数:48,代码来源:ipython_autoimport.py

示例3: __setattr__

# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __setattr__ [as 别名]
 def __setattr__(self, name, value):
     if hasattr(self, "_env"):
         self._env[name] = value
     ModuleType.__setattr__(self, name, value)
开发者ID:Psycojoker,项目名称:dawdaw,代码行数:6,代码来源:states.py

示例4: __setattr__

# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __setattr__ [as 别名]
    def __setattr__(self, name, value):
        if hasattr(self, "__readonly__"):
            if self.__readonly__ is True:
               raise Exception("This wrapper is marked as read only, it cannot be updated.")

        ModuleType.__setattr__(self, name, value)
开发者ID:MagicWishMonkey,项目名称:fuze,代码行数:8,代码来源:containers.py

示例5: __setattr__

# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __setattr__ [as 别名]
    def __setattr__(self, attr, value):
        if attr not in LazyModule.__reserved_attrs__:
            _loadModule(self)

        return ModuleType.__setattr__(self, attr, value)
开发者ID:Hamid-K,项目名称:deblaze,代码行数:7,代码来源:imports.py

示例6: __init__

# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __setattr__ [as 别名]
    def __init__(self, name, file, path=None):
        ModuleType.__setattr__(self, '__name__', name)
        ModuleType.__setattr__(self, '__file__', file)

        if path is not None:
            ModuleType.__setattr__(self, '__path__', path)
开发者ID:Hamid-K,项目名称:deblaze,代码行数:8,代码来源:imports.py

示例7: __setattr__

# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __setattr__ [as 别名]
 def __setattr__(self,attr,value):
     _loadModule(self)
     return ModuleType.__setattr__(self,attr,value)
开发者ID:mikedougherty,项目名称:peak,代码行数:5,代码来源:imports.py

示例8: __init__

# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __setattr__ [as 别名]
 def __init__(self, name):
     ModuleType.__setattr__(self,'__name__',name)
开发者ID:mikedougherty,项目名称:peak,代码行数:4,代码来源:imports.py

示例9: __setattr__

# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __setattr__ [as 别名]
 def __setattr__(self, name, value):
     #if hasattr(self, "instances"): self.instances[name] = value
     ModuleType.__setattr__(self, name, value)
开发者ID:KalielWilliamson,项目名称:Automated-Exoplanet-Search,代码行数:5,代码来源:releases.py


注:本文中的types.ModuleType.__setattr__方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。