class _NewClass(func_or_class): # pylint: disable=missing-docstring __doc__ = decorator_utils.add_notice_to_docstring( func_or_class.__doc__, 'Please use %s instead.' % name, 'DEPRECATED CLASS', '(deprecated)', [ 'THIS CLASS IS DEPRECATED. ' 'It will be removed in a future version. ' ]) __name__ = func_or_class.__name__ __module__ = _call_location(outer=True) @_wrap_decorator(func_or_class.__init__) def __init__(self, *args, **kwargs): if hasattr(_NewClass.__init__, '__func__'): # Python 2 _NewClass.__init__.__func__.__doc__ = func_or_class.__init__.__doc__ else: # Python 3 _NewClass.__init__.__doc__ = func_or_class.__init__.__doc__ if _PRINT_DEPRECATION_WARNINGS: # We're making the alias as we speak. The original may have other # aliases, so we cannot use it to check for whether it's already been # warned about. if _NewClass.__init__ not in _PRINTED_WARNING: if warn_once: _PRINTED_WARNING[_NewClass.__init__] = True logging.warning( 'From %s: The name %s is deprecated. Please use %s instead.\n', _call_location(), deprecated_name, name) super(_NewClass, self).__init__(*args, **kwargs)
def _add_experimental_function_notice_to_docstring(doc): """Adds an experimental notice to a docstring for experimental functions.""" return decorator_utils.add_notice_to_docstring( doc, '', 'EXPERIMENTAL FUNCTION', '(experimental)', [ 'THIS FUNCTION IS EXPERIMENTAL. It may change or ' 'be removed at any time, and without warning.' ])
def _add_deprecated_function_notice_to_docstring(doc, date, instructions): """Adds a deprecation notice to a docstring for deprecated functions.""" return decorator_utils.add_notice_to_docstring( doc, instructions, 'DEPRECATED FUNCTION', '(deprecated)', [ 'THIS FUNCTION IS DEPRECATED. It will be removed after %s.' % date, 'Instructions for updating:' ])
def _add_experimental_function_notice_to_docstring(doc): """Adds an experimental notice to a docstring for experimental functions.""" return decorator_utils.add_notice_to_docstring( doc, '', 'EXPERIMENTAL FUNCTION', '(experimental)', ['THIS FUNCTION IS EXPERIMENTAL. It may change or ' 'be removed at any time, and without warning.'])
def _add_deprecated_function_notice_to_docstring(doc, date, instructions): """Adds a deprecation notice to a docstring for deprecated functions.""" return decorator_utils.add_notice_to_docstring( doc, instructions, 'DEPRECATED FUNCTION', '(deprecated)', [ 'THIS FUNCTION IS DEPRECATED. It will be removed after %s.' % date, 'Instructions for updating:'])
def _check(self, doc, expected): self.assertEqual( decorator_utils.add_notice_to_docstring( doc=doc, instructions="Instructions", no_doc_str="Nothing here", suffix_str="(suffix)", notice=["Go away"]), expected)
def _add_deprecated_arg_notice_to_docstring(doc, date, instructions): """Adds a deprecation notice to a docstring for deprecated arguments.""" return decorator_utils.add_notice_to_docstring( doc, instructions, "DEPRECATED FUNCTION ARGUMENTS", "(deprecated arguments)", ["SOME ARGUMENTS ARE DEPRECATED. " "They will be removed after %s." % date, "Instructions for updating:"], )
def _check(self, doc, expected): self.assertEqual( decorator_utils.add_notice_to_docstring( doc=doc, instructions="Instructions", no_doc_str="Nothing here", suffix_str="(suffix)", notice=["Go away"]), expected)
def _add_deprecated_arg_notice_to_docstring(doc, date, instructions): """Adds a deprecation notice to a docstring for deprecated arguments.""" return decorator_utils.add_notice_to_docstring( doc, instructions, 'DEPRECATED FUNCTION ARGUMENTS', '(deprecated arguments)', [ 'SOME ARGUMENTS ARE DEPRECATED. ' 'They will be removed after %s.' % date, 'Instructions for updating:'])
def _add_deprecated_arg_notice_to_docstring(doc, date, instructions): """Adds a deprecation notice to a docstring for deprecated arguments.""" return decorator_utils.add_notice_to_docstring( doc, instructions, 'DEPRECATED FUNCTION ARGUMENTS', '(deprecated arguments)', [ 'SOME ARGUMENTS ARE DEPRECATED. ' 'They will be removed after %s.' % date, 'Instructions for updating:' ])
def _add_deprecated_function_notice_to_docstring(doc, date, instructions): """Adds a deprecation notice to a docstring for deprecated functions.""" return decorator_utils.add_notice_to_docstring( doc, instructions, "DEPRECATED FUNCTION", "(deprecated)", ["THIS FUNCTION IS DEPRECATED. It will be removed after %s." % date, "Instructions for updating:"], )
def _add_deprecated_function_notice_to_docstring(doc, date, instructions): """Adds a deprecation notice to a docstring for deprecated functions.""" main_text = ['THIS FUNCTION IS DEPRECATED. It will be removed %s.' % ('in a future version' if date is None else ('after %s' % date))] if instructions: main_text.append('Instructions for updating:') return decorator_utils.add_notice_to_docstring( doc, instructions, 'DEPRECATED FUNCTION', '(deprecated)', main_text)
def _add_deprecated_function_notice_to_docstring(doc, date, instructions): """Adds a deprecation notice to a docstring for deprecated functions.""" main_text = ['THIS FUNCTION IS DEPRECATED. It will be removed %s.' % ('in a future version' if date is None else ('after %s' % date))] if instructions: main_text.append('Instructions for updating:') return decorator_utils.add_notice_to_docstring( doc, instructions, 'DEPRECATED FUNCTION', '(deprecated)', main_text)
def _add_deprecated_arg_notice_to_docstring(doc, date, instructions, deprecated_names): """Adds a deprecation notice to a docstring for deprecated arguments.""" deprecation_string = ', '.join(sorted(deprecated_names)) return decorator_utils.add_notice_to_docstring( doc, instructions, 'DEPRECATED FUNCTION ARGUMENTS', '(deprecated arguments)', [ 'SOME ARGUMENTS ARE DEPRECATED: `(%s)`. ' 'They will be removed %s.' % (deprecation_string, 'in a future version' if date is None else ('after %s' % date)), 'Instructions for updating:' ])
def _add_deprecated_arg_notice_to_docstring(doc, date, instructions, deprecated_names): """Adds a deprecation notice to a docstring for deprecated arguments.""" deprecation_string = ', '.join(sorted(deprecated_names)) return decorator_utils.add_notice_to_docstring( doc, instructions, 'DEPRECATED FUNCTION ARGUMENTS', '(deprecated arguments)', [ 'SOME ARGUMENTS ARE DEPRECATED: `(%s)`. ' 'They will be removed %s.' % (deprecation_string, 'in a future version' if date is None else ('after %s' % date)), 'Instructions for updating:' ])
def _add_deprecated_arg_value_notice_to_docstring(doc, date, instructions, deprecated_name_value_dict): """Adds a deprecation notice to a docstring for deprecated arguments.""" deprecation_string = ', '.join( '%s=%r' % (key, value) for key, value in sorted(deprecated_name_value_dict.items())) when = 'in a future version' if date is None else ('after %s' % date) return decorator_utils.add_notice_to_docstring( doc, instructions, 'DEPRECATED FUNCTION ARGUMENT VALUES', '(deprecated argument values)', [ 'SOME ARGUMENT VALUES ARE DEPRECATED: `(%s)`. ' 'They will be removed %s.' % (deprecation_string, when), 'Instructions for updating:' ])
def _add_deprecated_arg_value_notice_to_docstring(doc, date, instructions, deprecated_name_value_dict): """Adds a deprecation notice to a docstring for deprecated arguments.""" deprecation_string = ', '.join( '%s=%r' % (key, value) for key, value in sorted(deprecated_name_value_dict.items())) when = 'in a future version' if date is None else ('after %s' % date) return decorator_utils.add_notice_to_docstring( doc, instructions, 'DEPRECATED FUNCTION ARGUMENT VALUES', '(deprecated argument values)', [ 'SOME ARGUMENT VALUES ARE DEPRECATED: `(%s)`. ' 'They will be removed %s.' % (deprecation_string, when), 'Instructions for updating:' ])