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


Python inspect.safe_getattr方法代码示例

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


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

示例1: get_module_members

# 需要导入模块: from sphinx.util import inspect [as 别名]
# 或者: from sphinx.util.inspect import safe_getattr [as 别名]
def get_module_members(module: Any) -> List[Tuple[str, Any]]:
    """Get members of target module."""
    from autodoc import INSTANCEATTR

    members = {}  # type: Dict[str, Tuple[str, Any]]
    for name in dir(module):
        try:
            value = safe_getattr(module, name, None)
            members[name] = (name, value)
        except AttributeError:
            continue

    # annotation only member (ex. attr: int)
    if hasattr(module, '__annotations__'):
        for name in module.__annotations__:
            if name not in members:
                members[name] = (name, INSTANCEATTR)

    return sorted(list(members.values())) 
开发者ID:thu-coai,项目名称:cotk,代码行数:21,代码来源:importer.py

示例2: get_object_members

# 需要导入模块: from sphinx.util import inspect [as 别名]
# 或者: from sphinx.util.inspect import safe_getattr [as 别名]
def get_object_members(self, want_all):
        if want_all:
            if not hasattr(self.object, '__all__'):
                # for implicit module members, check __module__ to avoid
                # documenting imported objects
                return True, safe_getmembers(self.object)
            else:
                memberlist = self.object.__all__
        else:
            memberlist = self.options.members or []
        ret = []
        for mname in memberlist:
            try:
                ret.append((mname, safe_getattr(self.object, mname)))
            except AttributeError:
                self.directive.warn(
                    'missing attribute mentioned in :members: or __all__: '
                    'module %s, attribute %s' % (
                    safe_getattr(self.object, '__name__', '???'), mname))
        return False, ret 
开发者ID:cihologramas,项目名称:pyoptools,代码行数:22,代码来源:sage_autodoc.py

示例3: get_members

# 需要导入模块: from sphinx.util import inspect [as 别名]
# 或者: from sphinx.util.inspect import safe_getattr [as 别名]
def get_members(doc, obj, typ, include_public=None, signal=False, enum=False):
        try:
            if not include_public:
                include_public = []
            items = []

            for name in dir(obj):
                if name not in obj.__dict__.keys():
                    continue
                try:
                    chobj = safe_getattr(obj, name)
                    documenter = get_documenter(doc.settings.env.app, chobj, obj)
                    #cl = get_class_that_defined_method(chobj)
                    #print(name, chobj.__qualname__, type(chobj), issubclass(chobj, Enum), documenter.objtype)
                    if documenter.objtype == typ:
                        if typ == 'attribute':
                            if signal and type(chobj) != PyQt5.QtCore.pyqtSignal:
                                continue
                            if not signal and type(chobj) == PyQt5.QtCore.pyqtSignal:
                                continue
                        elif typ == 'class':
                            if enum and not issubclass(chobj, Enum):
                                continue
                            if not enum and issubclass(chobj, Enum):
                                continue
                        items.append(name)
                except AttributeError:
                    continue
            public = [x for x in items if x in include_public or not x.startswith('_')]
            return public, items
        except BaseException as e:
            print(str(e))
            raise e 
开发者ID:qgis,项目名称:pyqgis,代码行数:35,代码来源:autoautosummary.py

示例4: get_members

# 需要导入模块: from sphinx.util import inspect [as 别名]
# 或者: from sphinx.util.inspect import safe_getattr [as 别名]
def get_members(clazz, obj, typ):
        names = set()
        items = []

        # the default dir
        for name in dir(obj):
            try:
                documenter = get_documenter(safe_getattr(obj, name), obj)
            except AttributeError:
                continue
            if documenter.objtype == typ and not name.startswith('_'):
                if name not in AutoCosmoSummary.exclude:
                    items.append((clazz,name))
                    names.add(name) # keep track of method/attribute conflicts

        # the delegate dro
        for n in obj.dro:
            for name in dir(n):
                try:
                    documenter = get_documenter(safe_getattr(n, name), n)
                except AttributeError:
                    continue

                # dont do conflicts
                if name not in names:
                    if documenter.objtype == typ and not name.startswith('_'):
                        if name not in AutoCosmoSummary.exclude:
                            x = "%s.%s" %(n.__module__, n.__name__)
                            items.append((x,name))
                            names.add(name)

        return ['~%s.%s' %item for item in sorted(items, key=lambda x: x[1])] 
开发者ID:bccp,项目名称:nbodykit,代码行数:34,代码来源:conf.py

示例5: get_members

# 需要导入模块: from sphinx.util import inspect [as 别名]
# 或者: from sphinx.util.inspect import safe_getattr [as 别名]
def get_members(obj, typ, public_only=True):
        items = []
        for name in dir(obj):
            if public_only and name.startswith('_'):
                continue
            try:
                documenter = get_documenter(None, safe_getattr(obj, name), obj)
            except AttributeError:
                continue
            if documenter.objtype == typ:
                items.append(name)
        return items 
开发者ID:civisanalytics,项目名称:civis-python,代码行数:14,代码来源:conf.py

示例6: get_members

# 需要导入模块: from sphinx.util import inspect [as 别名]
# 或者: from sphinx.util.inspect import safe_getattr [as 别名]
def get_members(obj, typ, include_public=None):
        if not include_public:
            include_public = []
        items = []
        for name in sorted(obj.__dict__.keys()):#dir(obj):
            try:
                documenter = get_documenter(AutoAutoSummary.app, safe_getattr(obj, name), obj)
            except AttributeError:
                continue
            if documenter.objtype in typ:
                items.append(name)
        public = [x for x in items if x in include_public or not x.startswith('_')]
        return public, items 
开发者ID:pyvista,项目名称:pyvista,代码行数:15,代码来源:conf.py

示例7: get_attr

# 需要导入模块: from sphinx.util import inspect [as 别名]
# 或者: from sphinx.util.inspect import safe_getattr [as 别名]
def get_attr(obj, name, *defargs):
        """getattr() override for types such as Zope interfaces."""
        for typ, func in AutoDirective._special_attrgetters.iteritems():
            if isinstance(obj, typ):
                return func(obj, name, *defargs)
        return safe_getattr(obj, name, *defargs) 
开发者ID:cihologramas,项目名称:pyoptools,代码行数:8,代码来源:sage_autodoc.py

示例8: add_content

# 需要导入模块: from sphinx.util import inspect [as 别名]
# 或者: from sphinx.util.inspect import safe_getattr [as 别名]
def add_content(self, more_content, no_docstring=False):
        if self.doc_as_attr:
            classname = safe_getattr(self.object, '__name__', None)
            if classname:
                content = ViewList(
                    [_('alias of :class:`%s`') % classname], source='')
                ModuleLevelDocumenter.add_content(self, content,
                                                  no_docstring=True)
        else:
            ModuleLevelDocumenter.add_content(self, more_content) 
开发者ID:cihologramas,项目名称:pyoptools,代码行数:12,代码来源:sage_autodoc.py

示例9: get_members

# 需要导入模块: from sphinx.util import inspect [as 别名]
# 或者: from sphinx.util.inspect import safe_getattr [as 别名]
def get_members(app, obj, typ, include_public=(), imported=False):
    items = []
    for name in dir(obj):
        try:
            obj_name = safe_getattr(obj, name)
            try:
                documenter = get_documenter(app, obj_name, obj)
            except TypeError:
                documenter = get_documenter(obj_name, obj)

        except AttributeError:
            continue
        if documenter.objtype == typ:
            try:
                cond = imported or (obj_name.__module__ == obj.__name__)
            except AttributeError:
                cond = True

            if cond:
                items.append(name)
    skip = set(app.config.autosummary_skip_members)
    _n = '{}.%s'.format(obj.__name__)

    public = [
        x for x in items
        if (x in include_public or not x.startswith('_')) and _n % x not in skip
    ]
    return public, items 
开发者ID:vinci1it2000,项目名称:schedula,代码行数:30,代码来源:autosummary.py

示例10: get_members

# 需要导入模块: from sphinx.util import inspect [as 别名]
# 或者: from sphinx.util.inspect import safe_getattr [as 别名]
def get_members(obj, typ, include_public=None):
        if not include_public:
            include_public = []
        items = []
        for name in dir(obj):
            try:
                documenter = get_documenter(safe_getattr(obj, name), obj)
            except AttributeError:
                continue
            if documenter.objtype == typ:
                items.append(name)
        public = [x for x in items if x in include_public or not x.startswith('_')]
        return public, items 
开发者ID:lucasrodes,项目名称:whatstk,代码行数:15,代码来源:conf.py

示例11: setup

# 需要导入模块: from sphinx.util import inspect [as 别名]
# 或者: from sphinx.util.inspect import safe_getattr [as 别名]
def setup(app):
    app.connect('autodoc-skip-member', skip_deprecated)
    try:
        from sphinx.ext.autosummary import Autosummary
        from sphinx.ext.autosummary import get_documenter
        from docutils.parsers.rst import directives
        from sphinx.util.inspect import safe_getattr

        class AutoAutoSummary(Autosummary):

            option_spec = {
                'methods': directives.unchanged,
                'attributes': directives.unchanged
            }

            required_arguments = 1

            @staticmethod
            def get_members(obj, typ, include_public=None):
                if not include_public:
                    include_public = []
                items = []
                for name in dir(obj):
                    try:
                        documenter = get_documenter(safe_getattr(obj, name),
                                                    obj)
                    except AttributeError:
                        continue
                    if documenter.objtype == typ:
                        items.append(name)
                public = [x for x in items
                          if x in include_public or not x.startswith('_')]
                return public, items

            def run(self):
                clazz = str(self.arguments[0])
                try:
                    (module_name, class_name) = clazz.rsplit('.', 1)
                    m = __import__(module_name, globals(), locals(),
                                   [class_name])
                    c = getattr(m, class_name)
                    if 'methods' in self.options:
                        _, methods = self.get_members(c,
                                                      'method', ['__init__'])

                        self.content = ["~%s.%s" % (clazz, method)
                                        for method in methods
                                        if not method.startswith('_')]
                    if 'attributes' in self.options:
                        _, attribs = self.get_members(c, 'attribute')
                        self.content = ["~%s.%s" % (clazz, attrib)
                                        for attrib in attribs
                                        if not attrib.startswith('_')]
                finally:
                    return super(AutoAutoSummary, self).run()

        app.add_directive('autoautosummary', AutoAutoSummary)
    except BaseException as e:
        raise e 
开发者ID:libvips,项目名称:pyvips,代码行数:61,代码来源:conf.py


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