本文整理汇总了Python中types.SimpleNamespace.value方法的典型用法代码示例。如果您正苦于以下问题:Python SimpleNamespace.value方法的具体用法?Python SimpleNamespace.value怎么用?Python SimpleNamespace.value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类types.SimpleNamespace
的用法示例。
在下文中一共展示了SimpleNamespace.value方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: extract_data_doc
# 需要导入模块: from types import SimpleNamespace [as 别名]
# 或者: from types.SimpleNamespace import value [as 别名]
def extract_data_doc(state: State, parent, path: List[str], data):
assert not inspect.ismodule(data) and not inspect.isclass(data) and not inspect.isroutine(data) and not inspect.isframe(data) and not inspect.istraceback(data) and not inspect.iscode(data)
out = Empty()
out.name = path[-1]
# Welp. https://stackoverflow.com/questions/8820276/docstring-for-variable
out.summary = ''
out.has_details = False
if hasattr(parent, '__annotations__') and out.name in parent.__annotations__:
out.type = extract_annotation(state, parent.__annotations__[out.name])
else:
out.type = None
# The autogenerated <foo.bar at 0xbadbeef> is useless, so provide the value
# only if __repr__ is implemented for given type
if '__repr__' in type(data).__dict__:
out.value = html.escape(repr(data))
else:
out.value = None
# External data summary, if provided
path_str = '.'.join(path)
if path_str in state.data_docs:
# TODO: use also the contents
out.summary = render_inline_rst(state, state.data_docs[path_str]['summary'])
del state.data_docs[path_str]
return out
示例2: extract_enum_doc
# 需要导入模块: from types import SimpleNamespace [as 别名]
# 或者: from types.SimpleNamespace import value [as 别名]
def extract_enum_doc(state: State, path: List[str], enum_):
out = Empty()
out.name = path[-1]
out.values = []
out.has_details = False
out.has_value_details = False
# The happy case
if issubclass(enum_, enum.Enum):
# Enum doc is by default set to a generic value. That's useless as well.
if enum_.__doc__ == 'An enumeration.':
out.summary = ''
else:
# TODO: external summary for enums
out.summary = extract_summary(state, {}, [], enum_.__doc__)
out.base = extract_type(enum_.__base__)
for i in enum_:
value = Empty()
value.name = i.name
value.value = html.escape(repr(i.value))
# Value doc gets by default inherited from the enum, that's useless
if i.__doc__ == enum_.__doc__:
value.summary = ''
else:
# TODO: external summary for enum values
value.summary = extract_summary(state, {}, [], i.__doc__)
if value.summary:
out.has_details = True
out.has_value_details = True
out.values += [value]
# Pybind11 enums are ... different
elif state.config['PYBIND11_COMPATIBILITY']:
assert hasattr(enum_, '__members__')
# TODO: external summary for enums
out.summary = extract_summary(state, {}, [], enum_.__doc__)
out.base = None
for name, v in enum_.__members__.items():
value = Empty()
value. name = name
value.value = int(v)
# TODO: once https://github.com/pybind/pybind11/pull/1160 is
# released, extract from class docs (until then the class
# docstring is duplicated here, which is useless)
value.summary = ''
out.values += [value]
return out