本文整理匯總了Python中deprecation.deprecated方法的典型用法代碼示例。如果您正苦於以下問題:Python deprecation.deprecated方法的具體用法?Python deprecation.deprecated怎麽用?Python deprecation.deprecated使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類deprecation
的用法示例。
在下文中一共展示了deprecation.deprecated方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: deprecated_test
# 需要導入模塊: import deprecation [as 別名]
# 或者: from deprecation import deprecated [as 別名]
def deprecated_test(test: Callable) -> Callable:
"""Marks a test as using deprecated functionality.
Ensures the test is executed within the `pytest.deprecated_call()` context.
Args:
test: The test.
Returns:
The decorated test.
"""
@functools.wraps(test)
def decorated_test(*args, **kwargs) -> Any:
with pytest.deprecated_call():
test(*args, **kwargs)
return decorated_test
示例2: test_multiline_fallback
# 需要導入模塊: import deprecation [as 別名]
# 或者: from deprecation import deprecated [as 別名]
def test_multiline_fallback(self):
docstring = "summary line\n\ndetails\nand more details\n"
for test in [{"args": {"deprecated_in": "1.0"},
"__doc__": "%s\n\n.. deprecated:: 1.0"}]:
with self.subTest(**test):
deprecation.message_location = "pot"
@deprecation.deprecated(**test["args"])
def fn():
"""summary line
details
and more details
"""
self.assertEqual(fn.__doc__, test["__doc__"] % (docstring))
示例3: rename_kwargs
# 需要導入模塊: import deprecation [as 別名]
# 或者: from deprecation import deprecated [as 別名]
def rename_kwargs(func_name, kwargs, aliases):
for alias, new in aliases.items():
if alias in kwargs:
if new in kwargs:
raise InvalidParamException(
'{} received both {} and {}'.format(func_name, alias, new))
# Manually invoke the deprecated decorator with an empty lambda
# to signal deprecation
deprecated(deprecated_in='1.1',
removed_in='2.0',
current_version=cloudbridge.__version__,
details='{} is deprecated, use {} instead'.format(
alias, new))(lambda: None)()
kwargs[new] = kwargs.pop(alias)
示例4: __setitem__
# 需要導入模塊: import deprecation [as 別名]
# 或者: from deprecation import deprecated [as 別名]
def __setitem__(self, key, value):
if not self._mutable:
warnings.warn("Modifying the project configuration after project "
"initialization is deprecated as of version 1.3 and "
"will be removed in version 2.0.",
DeprecationWarning)
assert version.parse(__version__) < version.parse("2.0")
return super(_ProjectConfig, self).__setitem__(key, value)
示例5: __init__
# 需要導入模塊: import deprecation [as 別名]
# 或者: from deprecation import deprecated [as 別名]
def __init__(self, project, filter, doc_filter):
self._project = project
self._filter = filter
self._doc_filter = doc_filter
# This private attribute allows us to implement the deprecated
# next() method for this class.
self._next_iter = None
示例6: next
# 需要導入模塊: import deprecation [as 別名]
# 或者: from deprecation import deprecated [as 別名]
def next(self):
"""Return the next element.
This function is deprecated, users should use iter(..).next() instead!
.. deprecated:: 0.9.6
"""
warnings.warn("Calling next() directly on a JobsCursor is deprecated!", DeprecationWarning)
if self._next_iter is None:
self._next_iter = iter(self)
try:
return next(self._next_iter)
except StopIteration:
self._next_iter = None
raise
示例7: deprecated_class
# 需要導入模塊: import deprecation [as 別名]
# 或者: from deprecation import deprecated [as 別名]
def deprecated_class(deprecated_in=None, removed_in=None, current_version=None, details=''):
def wrap(cls):
class DeprecatedClass(cls):
@deprecation.deprecated(deprecated_in=deprecated_in, removed_in=removed_in, current_version=current_version, details=details)
def __init__(self, *args, **kwargs):
super(DeprecatedClass, self).__init__(*args, **kwargs)
return DeprecatedClass
return wrap
示例8: __getitem__
# 需要導入模塊: import deprecation [as 別名]
# 或者: from deprecation import deprecated [as 別名]
def __getitem__(self, key):
if key == "root":
warnings.warn(
"WRADLIB: Use of `obj['root']` is deprecated, "
"please use obj.root instead.",
DeprecationWarning,
)
return self._root
return self._sweeps[key]
示例9: test_removing_without_deprecating
# 需要導入模塊: import deprecation [as 別名]
# 或者: from deprecation import deprecated [as 別名]
def test_removing_without_deprecating(self):
self.assertRaises(TypeError, deprecation.deprecated,
deprecated_in=None, removed_in="1.0")
示例10: test_docstring
# 需要導入模塊: import deprecation [as 別名]
# 或者: from deprecation import deprecated [as 別名]
def test_docstring(self):
for test in [{"args": {},
"__doc__": "docstring\n\n.. deprecated::"},
{"args": {"deprecated_in": "1.0"},
"__doc__": "docstring\n\n.. deprecated:: 1.0"},
{"args": {"deprecated_in": "1.0", "removed_in": "2.0"},
"__doc__": "docstring\n\n.. deprecated:: 1.0"
"\n This will be removed in 2.0."},
{"args": {"deprecated_in": "1.0", "removed_in": "2.0",
"details": "some details"},
"__doc__": "docstring\n\n.. deprecated:: 1.0"
"\n This will be removed in 2.0. "
"some details"},
{"args": {"deprecated_in": "1.0", "removed_in": date(2200, 5, 20)},
"__doc__": "docstring\n\n.. deprecated:: 1.0"
"\n This will be removed on 2200-05-20."},
{"args": {"deprecated_in": "1.0", "removed_in": date(2100, 3, 15),
"details": "some details"},
"__doc__": "docstring\n\n.. deprecated:: 1.0"
"\n This will be removed on 2100-03-15. "
"some details"}]:
with self.subTest(**test):
@deprecation.deprecated(**test["args"])
def fn():
"""docstring"""
self.assertEqual(fn.__doc__, test["__doc__"])
示例11: test_multiline_docstring
# 需要導入模塊: import deprecation [as 別名]
# 或者: from deprecation import deprecated [as 別名]
def test_multiline_docstring(self):
docstring = "summary line\n\ndetails\nand more details\n"
for test in [{"args": {},
"__doc__": "%s\n\n.. deprecated::"},
{"args": {"deprecated_in": "1.0"},
"__doc__": "%s\n\n.. deprecated:: 1.0"},
{"args": {"deprecated_in": "1.0", "removed_in": "2.0"},
"__doc__": "%s\n\n.. deprecated:: 1.0"
"\n This will be removed in 2.0."},
{"args": {"deprecated_in": "1.0", "removed_in": "2.0",
"details": "some details"},
"__doc__": "%s\n\n.. deprecated:: 1.0"
"\n This will be removed in 2.0. "
"some details"},
{"args": {"deprecated_in": "1.0", "removed_in": date(2200, 11, 20)},
"__doc__": "%s\n\n.. deprecated:: 1.0"
"\n This will be removed on 2200-11-20."},
{"args": {"deprecated_in": "1.0", "removed_in": date(2100, 3, 15),
"details": "some details"},
"__doc__": "%s\n\n.. deprecated:: 1.0"
"\n This will be removed on 2100-03-15. "
"some details"}]:
with self.subTest(**test):
@deprecation.deprecated(**test["args"])
def fn():
"""summary line
details
and more details
"""
self.assertEqual(fn.__doc__, test["__doc__"] % (docstring))
示例12: test_multiline_docstring_top
# 需要導入模塊: import deprecation [as 別名]
# 或者: from deprecation import deprecated [as 別名]
def test_multiline_docstring_top(self):
summary = "summary line"
content = "\n\ndetails\nand more details\n"
for test in [{"args": {},
"__doc__": "%s\n\n.. deprecated::%s"},
{"args": {"deprecated_in": "1.0"},
"__doc__": "%s\n\n.. deprecated:: 1.0%s"},
{"args": {"deprecated_in": "1.0", "removed_in": "2.0"},
"__doc__": "%s\n\n.. deprecated:: 1.0"
"\n This will be removed in 2.0.%s"},
{"args": {"deprecated_in": "1.0", "removed_in": "2.0",
"details": "some details"},
"__doc__": "%s\n\n.. deprecated:: 1.0"
"\n This will be removed in 2.0. "
"some details%s"},#####
{"args": {"deprecated_in": "1.0", "removed_in": date(2200, 11, 20)},
"__doc__": "%s\n\n.. deprecated:: 1.0"
"\n This will be removed on 2200-11-20.%s"},
{"args": {"deprecated_in": "1.0", "removed_in": date(2100, 3, 15),
"details": "some details"},
"__doc__": "%s\n\n.. deprecated:: 1.0"
"\n This will be removed on 2100-03-15. "
"some details%s"}]:
with self.subTest(**test):
deprecation.message_location = "top"
@deprecation.deprecated(**test["args"])
def fn():
"""summary line
details
and more details
"""
self.assertEqual(fn.__doc__, test["__doc__"] % (summary,
content))
示例13: _add_direct_cmd_arg_group
# 需要導入模塊: import deprecation [as 別名]
# 或者: from deprecation import deprecated [as 別名]
def _add_direct_cmd_arg_group(cls, parser):
direct_cmd_group = parser.add_argument_group("direct cmd")
direct_cmd_group.add_argument(
'--cmd',
type=str,
help="Directly specify the command for an operation. "
"For example: --cmd='echo {job._id}'. "
"--cmd option is deprecated as of 0.9 and will be removed in 0.11.")
direct_cmd_group.add_argument(
'--requires',
type=str,
nargs='+',
help="Manually specify all labels that are required for the direct command "
"to be considered eligible for execution.")
示例14: _main_script
# 需要導入模塊: import deprecation [as 別名]
# 或者: from deprecation import deprecated [as 別名]
def _main_script(self, args):
"Generate a script for the execution of operations."
if args.requires and not args.cmd:
raise ValueError(
"The --requires option can only be used in combination with --cmd.")
if args.cmd and args.operation_name:
raise ValueError(
"Cannot use the -o/--operation-name and the --cmd options in combination!")
# Select jobs:
jobs = self._select_jobs_from_args(args)
# Gather all pending operations or generate them based on a direct command...
with self._potentially_buffered():
if args.cmd:
warnings.warn("The --cmd option for script is deprecated as of "
"0.9 and will be removed in 0.11.",
DeprecationWarning)
operations = self._generate_operations(args.cmd, jobs, args.requires)
else:
names = args.operation_name if args.operation_name else None
default_directives = self._get_default_directives()
operations = self._get_submission_operations(jobs, default_directives, names,
args.ignore_conditions,
args.ignore_conditions_on_execution)
operations = list(islice(operations, args.num))
# Generate the script and print to screen.
print(self.script(
operations=operations, parallel=args.parallel,
template=args.template, show_template_help=args.show_template_help))
示例15: create_linked_view
# 需要導入模塊: import deprecation [as 別名]
# 或者: from deprecation import deprecated [as 別名]
def create_linked_view(self, prefix=None, job_ids=None, index=None, path=None):
"""Create or update a persistent linked view of the selected data space.
Similar to :meth:`~.export_to`, this function expands the data space for the selected
jobs, but instead of copying data will create symbolic links to the individual job
workspace directories. This is primarily useful for browsing through the data
space using a file-browser with human-interpretable directory paths.
By default, the paths of the view will be based on variable state point keys as part
of the *implicit* schema of the selected jobs that we create the view for. For example,
creating a linked view for a data space with schema
.. code-block:: python
>>> print(project.detect_schema())
{
'foo': 'int([0, 1, 2, ..., 8, 9], 10)',
}
by calling ``project.create_linked_view('my_view')`` will look similar to:
.. code-block:: bash
my_view/foo/0/job -> workspace/b8fcc6b8f99c56509eb65568922e88b8
my_view/foo/1/job -> workspace/b6cd26b873ae3624653c9268deff4485
...
It is possible to control the paths using the ``path`` argument, which behaves in
the exact same manner as the equivalent argument for :meth:`~.Project.export_to`.
.. note::
The behavior of this function is almost equivalent to
``project.export_to('my_view', copytree=os.symlink)`` with the major difference,
that view hierarchies are actually *updated*, that means no longer valid links
are automatically removed.
:param prefix:
The path where the linked view will be created or updated.
:type prefix:
str
:param job_ids:
If None (the default), create the view for the complete data space,
otherwise only for the sub space constituted by the provided job ids.
:param index:
A document index.
:param path:
The path (function) used to structure the linked data space.
:returns:
A dict that maps the source directory paths, to the linked
directory paths.
"""
if index is not None:
warnings.warn(("The `index` argument is deprecated as of version 1.3 and will be "
"removed in version 2.0."), DeprecationWarning)
from .linked_view import create_linked_view
return create_linked_view(self, prefix, job_ids, index, path)