本文整理匯總了Python中inspect.getdoc方法的典型用法代碼示例。如果您正苦於以下問題:Python inspect.getdoc方法的具體用法?Python inspect.getdoc怎麽用?Python inspect.getdoc使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類inspect
的用法示例。
在下文中一共展示了inspect.getdoc方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: handle_method
# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import getdoc [as 別名]
def handle_method(method, method_name, class_name):
method_errors = []
# Skip out-of-library inherited methods
module = inspect.getmodule(method)
if module is not None:
if not module.__name__.startswith('pylearn2'):
return method_errors
docstring = inspect.getdoc(method)
if docstring is None:
method_errors.append((class_name, method_name,
'**missing** method-level docstring'))
else:
method_errors = [
(class_name, method_name, e) for e in
NumpyFunctionDocString(docstring, method).get_errors()
]
return method_errors
示例2: handle_class
# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import getdoc [as 別名]
def handle_class(val, class_name):
cls_errors = []
docstring = inspect.getdoc(val)
if docstring is None:
cls_errors.append((class_name,
'**missing** class-level docstring'))
else:
cls_errors = [
(e,) for e in
NumpyClassDocString(docstring, class_name, val).get_errors()
]
# Get public methods and parse their docstrings
methods = dict(((name, func) for name, func in inspect.getmembers(val)
if not name.startswith('_') and callable(func) and
type(func) is not type))
for m_name, method in six.iteritems(methods):
# skip error check if the method was inherited
# from a parent class (which means it wasn't
# defined in this source file)
if inspect.getmodule(method) is not None:
continue
cls_errors.extend(handle_method(method, m_name, class_name))
return cls_errors
示例3: translateable_docstring
# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import getdoc [as 別名]
def translateable_docstring(cls):
@functools.wraps(cls.config_complete)
def config_complete(self, *args, **kwargs):
for command, func in get_commands(cls).items():
@functools.wraps(func)
def replacement(*args, **kwargs):
return func(self, *args, **kwargs)
replacement.__doc__ = self.strings["_cmd_doc_" + command]
setattr(self, command, replacement)
self.__doc__ = self.strings["_cls_doc"]
return self.config_complete._old_(self, *args, **kwargs)
config_complete._old_ = cls.config_complete
cls.config_complete = config_complete
for command, func in get_commands(cls).items():
cls.strings["_cmd_doc_" + command] = inspect.getdoc(func)
cls.strings["_cls_doc"] = inspect.getdoc(cls)
return cls
示例4: _get_docstring_fields
# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import getdoc [as 別名]
def _get_docstring_fields(self):
"""
Collect custom serializer fields described in serializer docstring
:rtype: OrderedDict
"""
if not inspect.isclass(self.serializer):
self.serializer = self.serializer.__class__
parser = YAMLDocstringParser()
for cls in inspect.getmro(self.serializer):
parser.update(inspect.getdoc(cls))
doc_fields = parser.schema.get('fields', OrderedDict())
return doc_fields
示例5: apply_purge_policies
# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import getdoc [as 別名]
def apply_purge_policies(selected_repos, policies_path=None, dryrun=True, default=True):
"""Sets up the plugins to find purgable artifacts and delete them.
Args:
selected_repos (list): List of repos to run against.
policies_path (str): Path to extra policies
dryrun (bool): If true, will not actually delete artifacts.
default (bool): If true, applies default policy to repos with no specific policy.
"""
plugin_source = setup_pluginbase(extra_policies_path=policies_path)
LOG.info("Applying retention policies to %s", ', '.join(selected_repos))
for repository in selected_repos:
artifactory_repo = Artifactory(repo_name=repository)
policy = get_policy(plugin_source, repository, default=default)
if not policy:
continue
LOG.info("Policy Docs: %s", inspect.getdoc(policy.purgelist))
artifacts = policy.purgelist(artifactory_repo)
purged_count = artifactory_repo.purge(dryrun, artifacts)
LOG.info("Processed %s, Purged %s", repository, purged_count)
示例6: assert_docstring_includes_param_metadata
# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import getdoc [as 別名]
def assert_docstring_includes_param_metadata(thing, path):
if inspect.isclass(thing):
return
docstring = inspect.getdoc(thing)
if not docstring:
return
for arg_name in inspect.getargspec(thing).args:
if arg_name in ("self", "cls"):
continue
if ":param %s:" % arg_name not in docstring:
raise AssertionError(
"Missing :param: for arg %s of %s" % (arg_name, path)
)
if ":type %s:" % arg_name not in docstring:
raise AssertionError(
"Missing :type: for arg %s of %s" % (arg_name, path)
)
示例7: _make_command
# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import getdoc [as 別名]
def _make_command(f, name, attrs, cls):
if isinstance(f, Command):
raise TypeError('Attempted to convert a callback into a '
'command twice.')
try:
params = f.__click_params__
params.reverse()
del f.__click_params__
except AttributeError:
params = []
help = attrs.get('help')
if help is None:
help = inspect.getdoc(f)
if isinstance(help, bytes):
help = help.decode('utf-8')
else:
help = inspect.cleandoc(help)
attrs['help'] = help
_check_for_unicode_literals()
return cls(name=name or f.__name__.lower().replace('_', '-'),
callback=f, params=params, **attrs)
示例8: analyse_action
# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import getdoc [as 別名]
def analyse_action(func):
"""Analyse a function."""
description = inspect.getdoc(func) or 'undocumented action'
arguments = []
args, varargs, kwargs, defaults = inspect.getargspec(func)
if varargs or kwargs:
raise TypeError('variable length arguments for action not allowed.')
if len(args) != len(defaults or ()):
raise TypeError('not all arguments have proper definitions')
for idx, (arg, definition) in enumerate(zip(args, defaults or ())):
if arg.startswith('_'):
raise TypeError('arguments may not start with an underscore')
if not isinstance(definition, tuple):
shortcut = None
default = definition
else:
shortcut, default = definition
argument_type = argument_types[type(default)]
if isinstance(default, bool) and default is True:
arg = 'no-' + arg
arguments.append((arg.replace('_', '-'), shortcut,
default, argument_type))
return func, description, arguments
示例9: _make_command
# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import getdoc [as 別名]
def _make_command(f, name, attrs, cls):
if isinstance(f, Command):
raise TypeError('Attempted to convert a callback into a '
'command twice.')
try:
params = f.__click_params__
params.reverse()
del f.__click_params__
except AttributeError:
params = []
help = attrs.get('help')
if help is None:
help = inspect.getdoc(f)
if isinstance(help, bytes):
help = help.decode('utf-8')
else:
help = inspect.cleandoc(help)
attrs['help'] = help
_check_for_unicode_literals()
return cls(name=name or f.__name__.lower(),
callback=f, params=params, **attrs)
示例10: _make_command
# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import getdoc [as 別名]
def _make_command(f, name, attrs, cls):
if isinstance(f, Command):
raise TypeError('Attempted to convert a callback into a '
'command twice.')
try:
params = f.__click_params__
params.reverse()
del f.__click_params__
except AttributeError:
params = []
help = attrs.get('help')
if help is None:
help = inspect.getdoc(f)
if isinstance(help, bytes):
help = help.decode('utf-8')
else:
help = inspect.cleandoc(help)
attrs['help'] = help
return cls(name=name or f.__name__.lower(),
callback=f, params=params, **attrs)
示例11: print_func
# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import getdoc [as 別名]
def print_func(name, func):
doc = inspect.getdoc(func)
sig = inspect.signature(func)
if not doc or (doc and not doc.strip()):
print(" {} -> {}".format(name.ljust(25), "UNDOCUMENTED"))
if not sig.parameters:
print(" No arguments")
else:
print(" Args: {}".format(sig))
else:
print(" {}".format(name))
if not sig.parameters:
print(" No arguments")
else:
print(" Args: {}".format(sig))
doclines = doc.splitlines()
for line in doclines:
print(" -> {}".format(line))
print()
示例12: __init__
# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import getdoc [as 別名]
def __init__(self, func, role='func', doc=None, config={}):
self._f = func
self._role = role # e.g. "func" or "meth"
if doc is None:
if func is None:
raise ValueError("No function or docstring given")
doc = inspect.getdoc(func) or ''
NumpyDocString.__init__(self, doc)
if not self['Signature'] and func is not None:
func, func_name = self.get_func()
try:
# try to read signature
argspec = inspect.getargspec(func)
argspec = inspect.formatargspec(*argspec)
argspec = argspec.replace('*', '\*')
signature = '%s%s' % (func_name, argspec)
except TypeError as e:
signature = '%s()' % func_name
self['Signature'] = signature
示例13: __str__
# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import getdoc [as 別名]
def __str__(self):
out = ''
doclines = inspect.getdoc(self._f) or ''
try:
doc = SphinxDocString(doclines)
except Exception as e:
print('*' * 78)
print("ERROR: '%s' while parsing `%s`" % (e, self._f))
print('*' * 78)
# print "Docstring follows:"
# print doclines
# print '='*78
return out
if doc['Signature']:
out += '%s\n' % header('**%s**' %
doc['Signature'].replace('*', '\\*'), '-')
else:
try:
# try to read signature
argspec = inspect.getargspec(self._f)
argspec = inspect.formatargspec(*argspec)
argspec = argspec.replace('*', '\\*')
out += header('%s%s' % (self._f.__name__, argspec), '-')
except TypeError as e:
out += '%s\n' % header('**%s()**' % self._f.__name__, '-')
out += str(doc)
return out
示例14: handle_function
# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import getdoc [as 別名]
def handle_function(val, name):
func_errors = []
docstring = inspect.getdoc(val)
if docstring is None:
func_errors.append((name, '**missing** function-level docstring'))
else:
func_errors = [
(name, e) for e in
NumpyFunctionDocString(docstring, val).get_errors()
]
return func_errors
示例15: __init__
# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import getdoc [as 別名]
def __init__(self, **kwargs):
self.runner = None
self.port = None
self.running = asyncio.Event()
self.ready = asyncio.Event()
self.client_data = {}
self._ratelimit_data = collections.defaultdict(dict)
self.app = web.Application(middlewares=[ratelimit(lambda f: self._ratelimit_data[f])])
aiohttp_jinja2.setup(self.app, filters={"getdoc": inspect.getdoc, "ascii": ascii},
loader=jinja2.FileSystemLoader("web-resources"))
self.app["static_root_url"] = "/static"
super().__init__(**kwargs)
self.app.router.add_static("/static/", "web-resources/static")