Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
docs = []
for func in set(self.values()):
try:
sig = inspect.signature(func)
except ValueError:
sig = ''
doc = func.__doc__ or ''
docs.append(f'{func.__name__}{sig}\n {doc}')
return '\n\n'.join(docs)
class multidispatch(multimethod):
"""Provisional wrapper for future compatibility with `functools.singledispatch`."""
get_type = multimethod(type)
get_type.__doc__ = """Return a generic `subtype` which checks subscripts."""
for atomic in (Iterator, str, bytes):
get_type[atomic,] = type
@multimethod # type: ignore[no-redef]
def get_type(arg: tuple):
"""Return generic type checking all values."""
return subtype(type(arg), *map(get_type, arg))
@multimethod # type: ignore[no-redef]
def get_type(arg: Mapping):
"""Return generic type checking first item."""
return subtype(type(arg), *map(get_type, next(iter(arg.items()), ())))
def __setitem__(self, key, value):
if callable(value):
value = getattr(self.get(key), 'register', multimethod)(value)
super().__setitem__(key, value)
@multimethod # type: ignore[no-redef]
def get_type(arg: tuple):
"""Return generic type checking all values."""
return subtype(type(arg), *map(get_type, arg))
@property
def docstring(self):
"""a descriptive docstring of all registered functions"""
docs = []
for func in set(self.values()):
try:
sig = inspect.signature(func)
except ValueError:
sig = ''
doc = func.__doc__ or ''
docs.append(f'{func.__name__}{sig}\n {doc}')
return '\n\n'.join(docs)
class multidispatch(multimethod):
"""Provisional wrapper for future compatibility with `functools.singledispatch`."""
get_type = multimethod(type)
get_type.__doc__ = """Return a generic `subtype` which checks subscripts."""
for atomic in (Iterator, str, bytes):
get_type[atomic,] = type
@multimethod # type: ignore[no-redef]
def get_type(arg: tuple):
"""Return generic type checking all values."""
return subtype(type(arg), *map(get_type, arg))
@multimethod # type: ignore[no-redef]