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

Function derived_from

dask/utils.py:964–1018  ·  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

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