|
9 | 9 | import types |
10 | 10 | import warnings |
11 | 11 | from inspect import signature |
| 12 | +from functools import wraps |
12 | 13 |
|
13 | | -from .codegen import make_function_with_signature |
14 | 14 | from .exceptions import (AstropyDeprecationWarning, AstropyUserWarning, |
15 | 15 | AstropyPendingDeprecationWarning) |
16 | 16 |
|
@@ -84,7 +84,7 @@ def deprecate_doc(old_doc, message): |
84 | 84 | old_doc = textwrap.dedent(old_doc).strip('\n') |
85 | 85 | new_doc = (('\n.. deprecated:: {since}' |
86 | 86 | '\n {message}\n\n'.format( |
87 | | - **{'since': since, 'message': message.strip()})) + old_doc) |
| 87 | + **{'since': since, 'message': message.strip()})) + old_doc) |
88 | 88 | if not old_doc: |
89 | 89 | # This is to prevent a spurious 'unexpected unindent' warning from |
90 | 90 | # docutils when the original docstring was blank. |
@@ -834,72 +834,6 @@ def _make_method(func, instance): |
834 | 834 | return types.MethodType(func, instance) |
835 | 835 |
|
836 | 836 |
|
837 | | -def wraps(wrapped, assigned=functools.WRAPPER_ASSIGNMENTS, |
838 | | - updated=functools.WRAPPER_UPDATES): |
839 | | - """ |
840 | | - An alternative to `functools.wraps` which also preserves the original |
841 | | - function's call signature by way of assigning the ``__signature__`` |
842 | | - attribute with the signature of the wrapped function. |
843 | | -
|
844 | | - The documentation for the original `functools.wraps` follows: |
845 | | - """ |
846 | | - |
847 | | - def wrapper(func): |
848 | | - func = functools.update_wrapper(func, wrapped, assigned=assigned, |
849 | | - updated=updated) |
850 | | - func.__signature__ = inspect.signature(wrapped) |
851 | | - return func |
852 | | - |
853 | | - return wrapper |
854 | | - |
855 | | - |
856 | | -if (isinstance(wraps.__doc__, str) and |
857 | | - wraps.__doc__ is not None and functools.wraps.__doc__ is not None): |
858 | | - wraps.__doc__ += functools.wraps.__doc__ |
859 | | - |
860 | | - |
861 | | -def _get_function_args_internal(func): |
862 | | - """ |
863 | | - Utility function for `wraps`. |
864 | | -
|
865 | | - Reads the argspec for the given function and converts it to arguments |
866 | | - for `make_function_with_signature`. |
867 | | - """ |
868 | | - |
869 | | - argspec = inspect.getfullargspec(func) |
870 | | - |
871 | | - if argspec.defaults: |
872 | | - args = argspec.args[:-len(argspec.defaults)] |
873 | | - kwargs = zip(argspec.args[len(args):], argspec.defaults) |
874 | | - else: |
875 | | - args = argspec.args |
876 | | - kwargs = [] |
877 | | - |
878 | | - if argspec.kwonlyargs: |
879 | | - kwargs.extend((argname, argspec.kwonlydefaults[argname]) |
880 | | - for argname in argspec.kwonlyargs) |
881 | | - |
882 | | - return {'args': args, 'kwargs': kwargs, 'varargs': argspec.varargs, |
883 | | - 'varkwargs': argspec.varkw} |
884 | | - |
885 | | - |
886 | | -def _get_function_args(func, exclude_args=()): |
887 | | - all_args = _get_function_args_internal(func) |
888 | | - |
889 | | - if exclude_args: |
890 | | - exclude_args = set(exclude_args) |
891 | | - |
892 | | - for arg_type in ('args', 'kwargs'): |
893 | | - all_args[arg_type] = [arg for arg in all_args[arg_type] |
894 | | - if arg not in exclude_args] |
895 | | - |
896 | | - for arg_type in ('varargs', 'varkwargs'): |
897 | | - if all_args[arg_type] in exclude_args: |
898 | | - all_args[arg_type] = None |
899 | | - |
900 | | - return all_args |
901 | | - |
902 | | - |
903 | 837 | def format_doc(docstring, *args, **kwargs): |
904 | 838 | """ |
905 | 839 | Replaces the docstring of the decorated object and then formats it. |
|
0 commit comments