My types happen to define __args__ which when used with multimethod raise the following error:
def __new__(cls, tp, *args):
if tp is Any:
return object
if hasattr(tp, '__supertype__'): # isinstance(..., NewType) only supported >=3.10
tp = tp.__supertype__
if isinstance(tp, TypeVar):
if not tp.__constraints__:
return object
tp = Union[tp.__constraints__]
origin = getattr(tp, '__origin__', tp)
if hasattr(types, 'UnionType') and isinstance(tp, types.UnionType):
origin = Union # `|` syntax added in 3.10
> args = tuple(map(cls, getattr(tp, '__args__', args)))
E TypeError: 'member_descriptor' object is not iterable
I modified multimethod's source to use the more robust typing.get_args() instead which fixed this issue.
My types happen to define
__args__
which when used with multimethod raise the following error:I modified multimethod's source to use the more robust
typing.get_args()
instead which fixed this issue.