Skip to content

Commit 11bca39

Browse files
Cadairmwcraig
authored andcommitted
go in even harder.
Python 3.5 just "does the right thing"
1 parent 7eac4b1 commit 11bca39

3 files changed

Lines changed: 6 additions & 69 deletions

File tree

‎astropy/modeling/core.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,8 @@ def __call__(self, **kwargs):
332332

333333
kwargs.append((param.name, param.default))
334334

335-
__call__ = make_function_with_signature(__call__, ('self',), kwargs)
335+
# __call__ = make_function_with_signature(__call__, ('self',), kwargs)
336+
__call__.__signature__ = sig
336337

337338
return type(str('_{0}BoundingBox'.format(cls.name)), (_BoundingBox,),
338339
{'__call__': __call__})

‎astropy/utils/codegen.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import textwrap
1212

1313
from .introspection import find_current_module
14+
from .decorators import deprecated
1415

1516

1617
__all__ = ['make_function_with_signature']
@@ -24,6 +25,7 @@
2425
"""
2526

2627

28+
@deprecated("3.1", "This function is no longer needed, directly use `inspect.Signature`.")
2729
def make_function_with_signature(func, args=(), kwargs={}, varargs=None,
2830
varkwargs=None, name=None):
2931
"""

‎astropy/utils/decorators.py‎

Lines changed: 2 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
import types
1010
import warnings
1111
from inspect import signature
12+
from functools import wraps
1213

13-
from .codegen import make_function_with_signature
1414
from .exceptions import (AstropyDeprecationWarning, AstropyUserWarning,
1515
AstropyPendingDeprecationWarning)
1616

@@ -84,7 +84,7 @@ def deprecate_doc(old_doc, message):
8484
old_doc = textwrap.dedent(old_doc).strip('\n')
8585
new_doc = (('\n.. deprecated:: {since}'
8686
'\n {message}\n\n'.format(
87-
**{'since': since, 'message': message.strip()})) + old_doc)
87+
**{'since': since, 'message': message.strip()})) + old_doc)
8888
if not old_doc:
8989
# This is to prevent a spurious 'unexpected unindent' warning from
9090
# docutils when the original docstring was blank.
@@ -834,72 +834,6 @@ def _make_method(func, instance):
834834
return types.MethodType(func, instance)
835835

836836

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-
903837
def format_doc(docstring, *args, **kwargs):
904838
"""
905839
Replaces the docstring of the decorated object and then formats it.

0 commit comments

Comments
 (0)