本文整理汇总了Python中sphinx.domains.ObjType方法的典型用法代码示例。如果您正苦于以下问题:Python domains.ObjType方法的具体用法?Python domains.ObjType怎么用?Python domains.ObjType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sphinx.domains
的用法示例。
在下文中一共展示了domains.ObjType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setup
# 需要导入模块: from sphinx import domains [as 别名]
# 或者: from sphinx.domains import ObjType [as 别名]
def setup(app):
# get the py domain
domain = app.registry.domains["py"]
# add the new "classattribute" object type and directive
domain.object_types["classattribute"] = ObjType(l_("classattribute"), "attr", "obj")
domain.directives["classattribute"] = pyd.PyClassmember
# patch get_index_text
PyClassmember__get_index_text = pyd.PyClassmember.get_index_text
def get_index_text(self, modname, name_cls):
text = PyClassmember__get_index_text(self, modname, name_cls)
if text != "":
return text
name, cls = name_cls
add_modules = self.env.config.add_module_names
if self.objtype == "classattribute":
try:
clsname, attrname = name.rsplit(".", 1)
except ValueError:
if modname:
return _("%s (in module %s)") % (name, modname)
else:
return name
if modname and add_modules:
return _("%s (%s.%s class attribute)") % (attrname, modname, clsname)
else:
return _("%s (%s class attribute)") % (attrname, clsname)
else:
return ""
pyd.PyClassmember.get_index_text = get_index_text
# patch get_signature_prefix
PyClassmember__get_signature_prefix = pyd.PyClassmember.get_signature_prefix
def get_signature_prefix(self, sig):
prefix = PyClassmember__get_signature_prefix(self, sig)
if prefix != "":
return prefix
if self.objtype == "classattribute":
return "classattribute "
else:
return ""
pyd.PyClassmember.get_signature_prefix = get_signature_prefix
return {"version": "patch"}