Skip to content

Commit

Permalink
Add instance __ua_convert__ wrapper.
Browse files Browse the repository at this point in the history
  • Loading branch information
hameerabbasi committed May 7, 2020
1 parent c9d9bdc commit 2adcd89
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions uarray/_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,3 +511,28 @@ def __ua_convert__(dispatchables, coerce):
return converted

return __ua_convert__


def wrap_single_convertor_instance(convert_single):
"""
Wraps a ``__ua_convert__`` defined for a single element to all elements.
If any of them return ``NotImplemented``, the operation is assumed to be
undefined.
Accepts a signature of (value, type, coerce).
"""

@functools.wraps(convert_single)
def __ua_convert__(self, dispatchables, coerce):
converted = []
for d in dispatchables:
c = convert_single(self, d.value, d.type, coerce and d.coercible)

if c is NotImplemented:
return NotImplemented

converted.append(c)

return converted

return __ua_convert__

0 comments on commit 2adcd89

Please sign in to comment.