Like functools.wraps, but safe to use even if wrapped is not a function. Only needed on Python 2.
(wrapped, assigned=functools.WRAPPER_ASSIGNMENTS)
| 404 | |
| 405 | |
| 406 | def safe_wraps(wrapped, assigned=functools.WRAPPER_ASSIGNMENTS): |
| 407 | """Like functools.wraps, but safe to use even if wrapped is not a function. |
| 408 | |
| 409 | Only needed on Python 2. |
| 410 | """ |
| 411 | if all(hasattr(wrapped, attr) for attr in assigned): |
| 412 | return functools.wraps(wrapped, assigned=assigned) |
| 413 | else: |
| 414 | return lambda x: x |
| 415 | |
| 416 | |
| 417 | def _dtype_of(a): |