本文整理汇总了Python中types.SimpleNamespace.name方法的典型用法代码示例。如果您正苦于以下问题:Python SimpleNamespace.name方法的具体用法?Python SimpleNamespace.name怎么用?Python SimpleNamespace.name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类types.SimpleNamespace
的用法示例。
在下文中一共展示了SimpleNamespace.name方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parse_syllabus
# 需要导入模块: from types import SimpleNamespace [as 别名]
# 或者: from types.SimpleNamespace import name [as 别名]
def parse_syllabus(syllabus_file, content_folder='', parse_all=False):
# loading raw syllabus
syll = split_into_units(syllabus_file)[0]
cell = syll.cells[1]
def section_to_name_date(line):
name = re.findall('\*\*(.*)\*\*', line)[0]
date = release_dates.get(name)
return name, date
def subs_to_name_file(line):
try:
file_name = re.findall(r'\((.+?\.ipynb)\)', line)[0]
except IndexError:
return
subsection_name = re.findall(r'\[(.+?)\]', line)[0]
return subsection_name, file_name
is_section = lambda line: line.startswith('*')
lines = cell['source'].split('\n')
sections = [section_to_name_date(line) for line in lines
if is_section(line)]
# Make a list of lines in each section.
subsections = (tuple(g) for k, g in groupby(lines, key=lambda x: not
is_section(x)) if k)
# Filter the actual subsections.
subsections = [[subs_to_name_file(i) for i in j if subs_to_name_file(i) is
not None] for j in subsections]
data = SimpleNamespace(category='main', chapters=[])
for i, section in enumerate(zip(sections, subsections)):
if not parse_all:
# Don't convert sections with no release date.
if section[0][1] is None:
continue
# creating chapter
chapter = SimpleNamespace(category='chapter', sequentials=[])
chapter.name = section[0][0]
chapter.date = section[0][1]
chapter.url = "sec_{0}".format(str(i).zfill(2))
for j, subsection in enumerate(section[1]):
# creating sequential
sequential = SimpleNamespace(category='sequential', verticals=[])
sequential.name = subsection[0]
sequential.date = chapter.date
sequential.url = "subsec_{0}_{1}".format(str(i).zfill(2),
str(j).zfill(2))
sequential.source_notebook = content_folder + '/' + subsection[1]
chapter.sequentials.append(sequential)
data.chapters.append(chapter)
return data
示例2: extract_enum_doc
# 需要导入模块: from types import SimpleNamespace [as 别名]
# 或者: from types.SimpleNamespace import name [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
示例3: extract_data_doc
# 需要导入模块: from types import SimpleNamespace [as 别名]
# 或者: from types.SimpleNamespace import name [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
示例4: setup
# 需要导入模块: from types import SimpleNamespace [as 别名]
# 或者: from types.SimpleNamespace import name [as 别名]
def setup(model_dir):
global model
opt = {}
opt = SimpleNamespace(**opt)
opt.nThreads = 1
opt.batchSize = 1
opt.serial_batches = True
opt.no_flip = True
opt.name = 'pretrained'
opt.checkpoints_dir = '.'
opt.model = 'pix2pix'
opt.which_direction = 'AtoB'
opt.norm = 'batch'
opt.input_nc = 3
opt.output_nc = 1
opt.which_model_netG = 'resnet_9blocks'
opt.no_dropout = True
opt.isTrain = False
opt.use_cuda = True
opt.ngf = 64
opt.ndf = 64
opt.init_type = 'normal'
opt.which_epoch = 'latest'
opt.pretrain_path = model_dir
model = create_model(opt)
return model
示例5: extract_class_doc
# 需要导入模块: from types import SimpleNamespace [as 别名]
# 或者: from types.SimpleNamespace import name [as 别名]
def extract_class_doc(state: State, path: List[str], class_):
assert inspect.isclass(class_)
out = Empty()
out.url = make_url(path)
out.name = path[-1]
out.summary = extract_summary(state, state.class_docs, path, class_.__doc__)
return out
示例6: extract_module_doc
# 需要导入模块: from types import SimpleNamespace [as 别名]
# 或者: from types.SimpleNamespace import name [as 别名]
def extract_module_doc(state: State, path: List[str], module):
assert inspect.ismodule(module)
out = Empty()
out.url = make_url(path)
out.name = path[-1]
out.summary = extract_summary(state, state.class_docs, path, module.__doc__)
return out
示例7: get_list
# 需要导入模块: from types import SimpleNamespace [as 别名]
# 或者: from types.SimpleNamespace import name [as 别名]
def get_list(self, page, sort_field, sort_desc, search, filters, page_size=None):
bukudb = self.bukudb
tags = bukudb.get_tag_all()[1]
tags = [(x, y) for x, y in tags.items()]
tags = self._apply_filters(tags, filters)
if sort_field == 'usage_count':
tags = sorted(tags, key=lambda x: x[1], reverse=sort_desc)
elif sort_field == 'name':
tags = sorted(tags, key=lambda x: x[0], reverse=sort_desc)
tags = list(tags)
count = len(tags)
if page_size and tags:
tags = list(chunks(tags, page_size))[page]
data = []
for name, usage_count in tags:
tag_sns = SimpleNamespace(name=None, usage_count=None)
tag_sns.name, tag_sns.usage_count = name, usage_count
data.append(tag_sns)
return count, data
示例8: extract_property_doc
# 需要导入模块: from types import SimpleNamespace [as 别名]
# 或者: from types.SimpleNamespace import name [as 别名]
def extract_property_doc(state: State, path: List[str], property):
assert inspect.isdatadescriptor(property)
out = Empty()
out.name = path[-1]
# TODO: external summary for properties
out.summary = extract_summary(state, {}, [], property.__doc__)
out.is_settable = property.fset is not None
out.is_deletable = property.fdel is not None
out.has_details = False
try:
signature = inspect.signature(property.fget)
out.type = extract_annotation(state, signature.return_annotation)
except ValueError:
# pybind11 properties have the type in the docstring
if state.config['PYBIND11_COMPATIBILITY']:
out.type = parse_pybind_signature(state, property.fget.__doc__)[3]
else:
out.type = None
return out
示例9: extract_function_doc
# 需要导入模块: from types import SimpleNamespace [as 别名]
# 或者: from types.SimpleNamespace import name [as 别名]
def extract_function_doc(state: State, parent, path: List[str], function) -> List[Any]:
assert inspect.isfunction(function) or inspect.ismethod(function) or inspect.isroutine(function)
# Extract the signature from the docstring for pybind11, since it can't
# expose it to the metadata: https://github.com/pybind/pybind11/issues/990
# What's not solvable with metadata, however, are function overloads ---
# one function in Python may equal more than one function on the C++ side.
# To make the docs usable, list all overloads separately.
if state.config['PYBIND11_COMPATIBILITY'] and function.__doc__.startswith(path[-1]):
funcs = parse_pybind_docstring(state, path[-1], function.__doc__)
overloads = []
for name, summary, args, type in funcs:
out = Empty()
out.name = path[-1]
out.params = []
out.has_complex_params = False
out.has_details = False
# TODO: external summary for functions
out.summary = summary
# Don't show None return type for void functions
out.type = None if type == 'None' else type
# There's no other way to check staticmethods than to check for
# self being the name of first parameter :( No support for
# classmethods, as C++11 doesn't have that
out.is_classmethod = False
if inspect.isclass(parent) and args and args[0][0] == 'self':
out.is_staticmethod = False
else:
out.is_staticmethod = True
# Guesstimate whether the arguments are positional-only or
# position-or-keyword. It's either all or none. This is a brown
# magic, sorry.
# For instance methods positional-only argument names are either
# self (for the first argument) or arg(I-1) (for second
# argument and further). Also, the `self` argument is
# positional-or-keyword only if there are positional-or-keyword
# arguments afgter it, otherwise it's positional-only.
if inspect.isclass(parent) and not out.is_staticmethod:
assert args and args[0][0] == 'self'
positional_only = True
for i, arg in enumerate(args[1:]):
name, type, default = arg
if name != 'arg{}'.format(i):
positional_only = False
break
# For static methods or free functions positional-only arguments
# are argI.
else:
positional_only = True
for i, arg in enumerate(args):
name, type, default = arg
if name != 'arg{}'.format(i):
positional_only = False
break
for i, arg in enumerate(args):
name, type, default = arg
param = Empty()
param.name = name
# Don't include redundant type for the self argument
if name == 'self': param.type = None
else: param.type = type
param.default = html.escape(default or '')
if type or default: out.has_complex_params = True
# *args / **kwargs can still appear in the parsed signatures if
# the function accepts py::args / py::kwargs directly
if name == '*args':
param.name = 'args'
param.kind = 'VAR_POSITIONAL'
elif name == '**kwargs':
param.name = 'kwargs'
param.kind = 'VAR_KEYWORD'
else:
param.kind = 'POSITIONAL_ONLY' if positional_only else 'POSITIONAL_OR_KEYWORD'
out.params += [param]
overloads += [out]
return overloads
# Sane introspection path for non-pybind11 code
else:
out = Empty()
out.name = path[-1]
out.params = []
out.has_complex_params = False
out.has_details = False
# TODO: external summary for functions
out.summary = extract_summary(state, {}, [], function.__doc__)
# Decide if classmethod or staticmethod in case this is a method
if inspect.isclass(parent):
#.........这里部分代码省略.........
示例10: load_module_members
# 需要导入模块: from types import SimpleNamespace [as 别名]
# 或者: from types.SimpleNamespace import name [as 别名]
def load_module_members(name, path):
module_spec = importlib.util.spec_from_file_location(name, path)
_module = importlib.util.module_from_spec(module_spec)
module_spec.loader.exec_module(_module)
return vars(_module)
errors_module = load_module_members('errors', CERBERUS_DIR / 'errors.py')
error_type = errors_module['ErrorDefinition']
error_definitions = []
for name, member in errors_module.items():
if not isinstance(member, error_type):
continue
error_definition = SimpleNamespace(**member._asdict())
error_definition.name = name
error_definitions.append(error_definition)
error_definitions.sort(key=attrgetter('code'))
with (INCLUDES_DIR / 'error-codes.rst').open('wt') as f:
print(
"""
.. list-table::
:header-rows: 1
* - Code (dec.)
- Code (hex.)
- Name
- Rule""".lstrip(
'\n'
),