本文整理汇总了Python中coalib.settings.FunctionMetadata.FunctionMetadata.from_function方法的典型用法代码示例。如果您正苦于以下问题:Python FunctionMetadata.from_function方法的具体用法?Python FunctionMetadata.from_function怎么用?Python FunctionMetadata.from_function使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类coalib.settings.FunctionMetadata.FunctionMetadata
的用法示例。
在下文中一共展示了FunctionMetadata.from_function方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_from_function
# 需要导入模块: from coalib.settings.FunctionMetadata import FunctionMetadata [as 别名]
# 或者: from coalib.settings.FunctionMetadata.FunctionMetadata import from_function [as 别名]
def test_from_function(self):
uut = FunctionMetadata.from_function(self.test_from_function)
self.check_function_metadata_data_set(uut, "test_from_function")
uut = FunctionMetadata.from_function(TestClass(5, 5).__init__)
self.check_function_metadata_data_set(uut,
"__init__",
desc="Description",
retval_desc="ret",
non_optional_params={
"param1": (uut.str_nodesc, None),
"param2": ("d", None)
},
optional_params={
"param3": (uut.str_nodesc + " (" + uut.str_optional.format("5") + ")",
None, 5),
"param4": ("p4 desc (" + uut.str_optional.format("6") + ")", int, 6)
})
uut = FunctionMetadata.from_function(TestClass(5, 5).__init__, omit=["param3", "param2"])
self.check_function_metadata_data_set(uut,
"__init__",
desc="Description",
retval_desc="ret",
non_optional_params={
"param1": (uut.str_nodesc, None)
},
optional_params={
"param4": ("p4 desc (" + uut.str_optional.format("6") + ")", int, 6)
})
示例2: test_create_params_from_section_invalid
# 需要导入模块: from coalib.settings.FunctionMetadata import FunctionMetadata [as 别名]
# 或者: from coalib.settings.FunctionMetadata.FunctionMetadata import from_function [as 别名]
def test_create_params_from_section_invalid(self):
section = Section("name")
section.append(Setting("bad_param", "value"))
uut = FunctionMetadata.from_function(TestClass(5, 5).bad_function)
with self.assertRaises(ValueError):
uut.create_params_from_section(section)
示例3: get_metadata
# 需要导入模块: from coalib.settings.FunctionMetadata import FunctionMetadata [as 别名]
# 或者: from coalib.settings.FunctionMetadata.FunctionMetadata import from_function [as 别名]
def get_metadata(cls):
"""
:return: Metadata for the run function. However parameters like
``self`` or parameters implicitly used by coala (e.g.
filename for local bears) are already removed.
"""
return FunctionMetadata.from_function(cls.run, omit={"self", "dependency_results"})
示例4: get_metadata
# 需要导入模块: from coalib.settings.FunctionMetadata import FunctionMetadata [as 别名]
# 或者: from coalib.settings.FunctionMetadata.FunctionMetadata import from_function [as 别名]
def get_metadata(cls):
return FunctionMetadata.merge(
FunctionMetadata.from_function(
cls.run,
omit={"self", "dependency_results"}),
cls.get_shortlog_checks_metadata(),
cls.get_body_checks_metadata())
示例5: _deprecate_decorator
# 需要导入模块: from coalib.settings.FunctionMetadata import FunctionMetadata [as 别名]
# 或者: from coalib.settings.FunctionMetadata.FunctionMetadata import from_function [as 别名]
def _deprecate_decorator(func):
def wrapping_function(*args, **kwargs):
for arg, depr_arg_and_modifier in depr_args.items():
deprecated_arg, _func = (
depr_arg_and_modifier
if isinstance(depr_arg_and_modifier, tuple)
else (depr_arg_and_modifier, lambda x: x))
if deprecated_arg in kwargs:
print("The setting `{}` is deprecated. Please use `{}` "
"instead.".format(deprecated_arg, arg))
depr_arg_value = _func.__call__(kwargs[deprecated_arg])
if arg in kwargs and depr_arg_value != kwargs[arg]:
print('The value of `{}` and `{}` are conflicting.'
' `{}` will be used instead.'.format(
deprecated_arg, arg, arg))
else:
kwargs[arg] = depr_arg_value
del kwargs[deprecated_arg]
return func(*args, **kwargs)
new_metadata = FunctionMetadata.from_function(func)
for arg, depr_arg_and_modifier in depr_args.items():
deprecated_arg = (depr_arg_and_modifier[0]
if isinstance(depr_arg_and_modifier, tuple)
else depr_arg_and_modifier)
new_metadata.add_alias(arg, deprecated_arg)
wrapping_function.__metadata__ = new_metadata
return wrapping_function
示例6: _func_decorator
# 需要导入模块: from coalib.settings.FunctionMetadata import FunctionMetadata [as 别名]
# 或者: from coalib.settings.FunctionMetadata.FunctionMetadata import from_function [as 别名]
def _func_decorator(func):
@wraps(func)
def _new_func(self, *args, **kwargs):
if not self.section.aspects:
return func(self, *args, **kwargs)
aspects = self.section.aspects
for arg, aspect_value in aspectable_settings.items():
# Explicit bear setting takes priority over aspects
if arg in self.section:
continue
taste, aspect_settings = aspect_value
aspect_instance = aspects.get(taste.aspect_name)
if aspect_instance:
value = aspect_instance.tastes[taste.name]
for value_pair in aspect_value[1]:
if value_pair[0] == value:
kwargs[arg] = value_pair[1]
return func(self, *args, **kwargs)
# Keep metadata
_new_func.__metadata__ = FunctionMetadata.from_function(func)
return _new_func
示例7: get_metadata
# 需要导入模块: from coalib.settings.FunctionMetadata import FunctionMetadata [as 别名]
# 或者: from coalib.settings.FunctionMetadata.FunctionMetadata import from_function [as 别名]
def get_metadata(cls):
return FunctionMetadata.merge(
FunctionMetadata.from_function(
cls.run,
omit={'self', 'dependency_results'}),
cls.get_shortlog_checks_metadata(),
cls.get_body_checks_metadata(),
cls.get_issue_checks_metadata())
示例8: get_metadata
# 需要导入模块: from coalib.settings.FunctionMetadata import FunctionMetadata [as 别名]
# 或者: from coalib.settings.FunctionMetadata.FunctionMetadata import from_function [as 别名]
def get_metadata(cls):
"""
:return:
Metadata for the ``analyze`` function extracted from its signature.
Excludes parameters ``self``, ``filename`` and ``file``.
"""
return FunctionMetadata.from_function(
cls.analyze,
omit={'self', 'filename', 'file'})
示例9: _deprecate_decorator
# 需要导入模块: from coalib.settings.FunctionMetadata import FunctionMetadata [as 别名]
# 或者: from coalib.settings.FunctionMetadata.FunctionMetadata import from_function [as 别名]
def _deprecate_decorator(func):
logged_deprecated_args = set()
@wraps(func)
def wrapping_function(*args, **kwargs):
for arg, depr_value in wrapping_function.__metadata__.depr_values:
deprecated_arg = depr_value[0]
_func = depr_value[1]
if deprecated_arg in kwargs:
if deprecated_arg not in logged_deprecated_args:
logging.warning(
'The setting `{}` is deprecated. Please use `{}` '
'instead.'.format(deprecated_arg, arg))
logged_deprecated_args.add(deprecated_arg)
depr_arg_value = _func.__call__(kwargs[deprecated_arg])
if arg in kwargs and depr_arg_value != kwargs[arg]:
logging.warning(
'The value of `{}` and `{}` are conflicting.'
' `{}` will be used instead.'.format(
deprecated_arg, arg, arg))
else:
kwargs[arg] = depr_arg_value
del kwargs[deprecated_arg]
return func(*args, **kwargs)
new_metadata = FunctionMetadata.from_function(func)
new_metadata.depr_values = []
for arg, depr_values in depr_args.items():
if not isinstance(depr_values, tuple):
depr_values = (depr_values,)
if callable(depr_values[-1]):
deprecated_args = depr_values[:-1]
default_modifier = depr_values[-1]
else:
deprecated_args = depr_values
default_modifier = _do_nothing
for depr_value in deprecated_args:
if isinstance(depr_value, dict):
deprecated_arg = list(depr_value.keys())[0]
modifier = depr_value[deprecated_arg]
new_metadata.depr_values.append((arg,
(deprecated_arg,
modifier)))
else:
deprecated_arg = depr_value
new_metadata.depr_values.append((arg,
(deprecated_arg,
default_modifier)))
new_metadata.add_deprecated_param(arg, deprecated_arg)
wrapping_function.__metadata__ = new_metadata
return wrapping_function
示例10: test_from_function
# 需要导入模块: from coalib.settings.FunctionMetadata import FunctionMetadata [as 别名]
# 或者: from coalib.settings.FunctionMetadata.FunctionMetadata import from_function [as 别名]
def test_from_function(self):
uut = FunctionMetadata.from_function(self.test_from_function)
self.check_function_metadata_data_set(uut, 'test_from_function')
# setattr on bound methods will fail, vars() will use the dict from
# the unbound method which is ok.
vars(self.test_from_function)['__metadata__'] = (
FunctionMetadata('t'))
uut = FunctionMetadata.from_function(self.test_from_function)
self.check_function_metadata_data_set(uut, 't')
uut = FunctionMetadata.from_function(TestClass(5, 5).__init__)
self.check_function_metadata_data_set(
uut,
'__init__',
desc='Description',
retval_desc='ret',
non_optional_params={
'param1': (uut.str_nodesc, None),
'param2': ('d', None)
},
optional_params={
'param3': (uut.str_nodesc + ' ('
+ uut.str_optional.format('5') + ')',
None, 5),
'param4': ('p4 desc ('
+ uut.str_optional.format('6') + ')', int, 6)})
uut = FunctionMetadata.from_function(TestClass(5, 5).__init__,
omit={'param3', 'param2'})
self.check_function_metadata_data_set(
uut,
'__init__',
desc='Description',
retval_desc='ret',
non_optional_params={
'param1': (uut.str_nodesc,
None)
},
optional_params={
'param4': ('p4 desc (' + uut.str_optional.format('6') + ')',
int,
6)})
示例11: test_from_function
# 需要导入模块: from coalib.settings.FunctionMetadata import FunctionMetadata [as 别名]
# 或者: from coalib.settings.FunctionMetadata.FunctionMetadata import from_function [as 别名]
def test_from_function(self):
uut = FunctionMetadata.from_function(self.test_from_function)
self.check_function_metadata_data_set(uut, "test_from_function")
# setattr on bound methods will fail, __dict__ will use the dict from
# the unbound method which is ok.
self.test_from_function.__dict__["__metadata__"] = (
FunctionMetadata("t"))
uut = FunctionMetadata.from_function(self.test_from_function)
self.check_function_metadata_data_set(uut, "t")
uut = FunctionMetadata.from_function(TestClass(5, 5).__init__)
self.check_function_metadata_data_set(
uut,
"__init__",
desc="Description",
retval_desc="ret",
non_optional_params={
"param1": (uut.str_nodesc, None),
"param2": ("d", None)
},
optional_params={
"param3": (uut.str_nodesc + " ("
+ uut.str_optional.format("5") + ")",
None, 5),
"param4": ("p4 desc ("
+ uut.str_optional.format("6") + ")", int, 6)})
uut = FunctionMetadata.from_function(TestClass(5, 5).__init__,
omit={"param3", "param2"})
self.check_function_metadata_data_set(
uut,
"__init__",
desc="Description",
retval_desc="ret",
non_optional_params={
"param1": (uut.str_nodesc,
None)
},
optional_params={
"param4": ("p4 desc (" + uut.str_optional.format("6") + ")",
int,
6)})
示例12: test_create_params_from_section_valid
# 需要导入模块: from coalib.settings.FunctionMetadata import FunctionMetadata [as 别名]
# 或者: from coalib.settings.FunctionMetadata.FunctionMetadata import from_function [as 别名]
def test_create_params_from_section_valid(self):
section = Section("name")
section.append(Setting("a_param", "value"))
uut = FunctionMetadata.from_function(TestClass(5, 5).good_function)
with self.assertRaises(ValueError):
uut.create_params_from_section(section)
section.append(Setting("a_param", "5"))
params = uut.create_params_from_section(section)
self.assertEqual(params['a_param'], 5)
示例13: _get_process_output_metadata
# 需要导入模块: from coalib.settings.FunctionMetadata import FunctionMetadata [as 别名]
# 或者: from coalib.settings.FunctionMetadata.FunctionMetadata import from_function [as 别名]
def _get_process_output_metadata(cls):
metadata = FunctionMetadata.from_function(cls.process_output)
if options["output_format"] is None:
omitted = {"self", "output", "filename", "file"}
else:
# If a specific output format is provided, function signatures
# from process_output functions should not appear in the help.
omitted = set(chain(metadata.non_optional_params,
metadata.optional_params))
metadata.omit = omitted
return metadata
示例14: get_metadata
# 需要导入模块: from coalib.settings.FunctionMetadata import FunctionMetadata [as 别名]
# 或者: from coalib.settings.FunctionMetadata.FunctionMetadata import from_function [as 别名]
def get_metadata(cls):
"""
Retrieves metadata for the apply function. The description may be used
to advertise this action to the user. The parameters and their help
texts are additional information that are needed from the user. You can
create a section out of the inputs from the user and use
apply_from_section to apply
:return A FunctionMetadata object.
"""
data = FunctionMetadata.from_function(
cls.apply,
omit={'self', 'result', 'original_file_dict', 'file_diff_dict'})
data.name = cls.__name__
return data
示例15: default
# 需要导入模块: from coalib.settings.FunctionMetadata import FunctionMetadata [as 别名]
# 或者: from coalib.settings.FunctionMetadata.FunctionMetadata import from_function [as 别名]
def default(self, obj):
if hasattr(obj, "__json__"):
fdata = FunctionMetadata.from_function(obj.__json__)
params = self._filter_params(
fdata.optional_params, fdata.non_optional_params)
return obj.__json__(**params)
elif isinstance(obj, collections.Iterable):
return list(obj)
elif isinstance(obj, datetime):
return obj.isoformat()
elif hasattr(obj, "__getitem__") and hasattr(obj, "keys"):
return dict(obj)
elif hasattr(obj, "__dict__"):
return {member: getattr(obj, member)
for member in get_public_members(obj)}
return json.JSONEncoder.default(self, obj)