MCPcopy Create free account
hub / github.com/dask/dask / derived_from

Function derived_from

dask/utils.py:961–1015  ·  view source on GitHub ↗

Decorator to attach original class's docstring to the wrapped method. The output structure will be: top line of docstring, disclaimer about this being auto-derived, any extra text associated with the method being patched, the body of the docstring and finally, the list of keywords that

(
    original_klass, version=None, ua_args=None, skipblocks=0, inconsistencies=None
)

Source from the content-addressed store, hash-verified

959
960
961def derived_from(
962 original_klass, version=None, ua_args=None, skipblocks=0, inconsistencies=None
963):
964 """Decorator to attach original class's docstring to the wrapped method.
965
966 The output structure will be: top line of docstring, disclaimer about this
967 being auto-derived, any extra text associated with the method being patched,
968 the body of the docstring and finally, the list of keywords that exist in
969 the original method but not in the dask version.
970
971 Parameters
972 ----------
973 original_klass: type
974 Original class which the method is derived from
975 version : str
976 Original package version which supports the wrapped method
977 ua_args : list
978 List of keywords which Dask doesn't support. Keywords existing in
979 original but not in Dask will automatically be added.
980 skipblocks : int
981 How many text blocks (paragraphs) to skip from the start of the
982 docstring. Useful for cases where the target has extra front-matter.
983 inconsistencies: list
984 List of known inconsistencies with method whose docstrings are being
985 copied.
986 """
987 ua_args = ua_args or []
988
989 def wrapper(method):
990 try:
991 extra = getattr(method, "__doc__", None) or ""
992 method.__doc__ = _derived_from(
993 original_klass,
994 method,
995 ua_args=ua_args,
996 extra=extra,
997 skipblocks=skipblocks,
998 inconsistencies=inconsistencies,
999 )
1000 return method
1001
1002 except AttributeError:
1003 module_name = original_klass.__module__.split(".")[0]
1004
1005 @functools.wraps(method)
1006 def wrapped(*args, **kwargs):
1007 msg = f"Base package doesn't support '{method.__name__}'."
1008 if version is not None:
1009 msg2 = " Use {0} {1} or later to use this method."
1010 msg += msg2.format(module_name, version)
1011 raise NotImplementedError(msg)
1012
1013 return wrapped
1014
1015 return wrapper
1016
1017
1018def funcname(func) -> str:

Callers 6

_bind_methodFunction · 0.90
_bind_propertyFunction · 0.90
wrap_elemwiseFunction · 0.90
__init__Method · 0.90
wrap_elemwiseFunction · 0.90
__init__Method · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected