[SciPy-dev] scipy.stats._chk_asarray

josef.pktd@gmai... josef.pktd@gmai...
Wed Jun 3 09:10:00 CDT 2009


On Wed, Jun 3, 2009 at 9:42 AM, Ryan May <rmay31@gmail.com> wrote:
> On Wed, Jun 3, 2009 at 2:33 AM, Pauli Virtanen <pav@iki.fi> wrote:
>>
>> Wed, 03 Jun 2009 02:17:56 -0400, Pierre GM kirjoitti:
>> [clip]
>> > def keepthetype(func):
>> >      def wrapped(*args, **kwargs):
>> >          first = args[0]
>> >          if isinstance(first, np.ndarray):
>> >              output_type = type(first)
>> >          else:
>> >              output_type = np.ndarray
>> >          output = func(*args, **kwargs)
>> >          if isinstance(output, np.ndarray):
>> >              return output.view(output_type)
>> >          return output
>> >      wrapped.__name__ = func.__name__
>> >      wrapped.__dict__ = func.__dict__
>> >      wrapped.__doc__ = func.__doc__
>> >      return wrapped
>>
>> This is not enough to preserve the function signature, which is quite
>> annoying from the help-POV. It's probably best to take a look at the
>> decorator.py:
>>
>> http://pypi.python.org/pypi/decorator/3.0.1
>>
>
> There's functools.update_wrapper and functools.wraps in the standard
> library.  Would those be enough?  (The docs make it seem simple enough.)
>
functools was added in python 2.5

Running a simple example of wraps from PMOTW, doesn't look like it's
trivial to get np.source and help in an editor to work, for example
pydee shows the source when the function is not wrapped, but I only
get the decorator source for the wrapped function. I'm not sure what
the signature is showing.

> Ryan


More information about the Scipy-dev mailing list