From 8d3ea51349c0d7a06900c1e282a386485ddad218 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20H=C3=B8xbro?= Date: Tue, 27 Dec 2022 16:53:30 +0100 Subject: [PATCH] Remove add_metaclass --- holoviews/core/accessors.py | 11 +++-------- holoviews/core/data/__init__.py | 19 +++++++++---------- holoviews/plotting/plotly/callbacks.py | 5 +---- 3 files changed, 13 insertions(+), 22 deletions(-) diff --git a/holoviews/core/accessors.py b/holoviews/core/accessors.py index 921902d5a2..1b473082d5 100644 --- a/holoviews/core/accessors.py +++ b/holoviews/core/accessors.py @@ -10,8 +10,6 @@ import param -from param.parameterized import add_metaclass - from . import util from .pprint import PrettyPrinter @@ -85,8 +83,7 @@ def pipelined_call(*args, **kwargs): return pipelined_call -@add_metaclass(AccessorPipelineMeta) -class Apply: +class Apply(metaclass=AccessorPipelineMeta): """ Utility to apply a function or operation to all viewable elements inside the object. @@ -288,8 +285,7 @@ def transform(self, *args, **kwargs): return self.__call__('transform', **kwargs) -@add_metaclass(AccessorPipelineMeta) -class Redim: +class Redim(metaclass=AccessorPipelineMeta): """ Utility that supports re-dimensioning any HoloViews object via the redim method. @@ -488,8 +484,7 @@ def values(self, specs=None, **ranges): return self._redim('values', specs, **ranges) -@add_metaclass(AccessorPipelineMeta) -class Opts: +class Opts(metaclass=AccessorPipelineMeta): def __init__(self, obj, mode=None): self._mode = mode diff --git a/holoviews/core/data/__init__.py b/holoviews/core/data/__init__.py index c7e705a39d..28d08c71c5 100644 --- a/holoviews/core/data/__init__.py +++ b/holoviews/core/data/__init__.py @@ -8,7 +8,7 @@ import param import pandas as pd # noqa -from param.parameterized import add_metaclass, ParameterizedMetaclass +from param.parameterized import ParameterizedMetaclass from ..accessors import Redim from ..dimension import ( @@ -236,8 +236,7 @@ def pipelined_fn(*args, **kwargs): return pipelined_fn -@add_metaclass(PipelineMeta) -class Dataset(Element): +class Dataset(Element, metaclass=PipelineMeta): """ Dataset provides a general baseclass for Element types that contain structured data and supports a range of data formats. @@ -290,7 +289,7 @@ class to each underlying element. cls.param.warning(cls, msg.format(class_name=class_name, apply_args=apply_args)) return data.apply(cls, per_element=True, kdims=kdims, vdims=vdims, **kwargs) else: - return super(Dataset, cls).__new__(cls) + return super().__new__(cls) def __init__(self, data, kdims=None, vdims=None, **kwargs): from ...operation.element import ( @@ -332,7 +331,7 @@ def __init__(self, data, kdims=None, vdims=None, **kwargs): initialized = Interface.initialize(type(self), data, kdims, vdims, datatype=kwargs.get('datatype')) (data, self.interface, dims, extra_kws) = initialized - super(Dataset, self).__init__(data, **dict(kwargs, **dict(dims, **extra_kws))) + super().__init__(data, **dict(kwargs, **dict(dims, **extra_kws))) self.interface.validate(self, validate_vdims) # Handle _pipeline property @@ -369,7 +368,7 @@ def __init__(self, data, kdims=None, vdims=None, **kwargs): def __getstate__(self): "Ensures pipelines are dropped" - obj_dict = super(Dataset, self).__getstate__() + obj_dict = super().__getstate__() if '_pipeline' in obj_dict: pipeline = obj_dict['_pipeline'] obj_dict['_pipeline'] = pipeline.instance(operations=pipeline.operations[:1]) @@ -1195,21 +1194,21 @@ def clone(self, data=None, shared_data=True, new_type=None, link=True, elif self._in_method and 'dataset' not in overrides: overrides['dataset'] = self.dataset - return super(Dataset, self).clone(data, shared_data, new_type, *args, **overrides) + return super().clone(data, shared_data, new_type, *args, **overrides) # Overrides of superclass methods that are needed so that PipelineMeta # will find them to wrap with pipeline support @wraps(Dimensioned.options) def options(self, *args, **kwargs): - return super(Dataset, self).options(*args, **kwargs) + return super().options(*args, **kwargs) @wraps(LabelledData.map) def map(self, *args, **kwargs): - return super(Dataset, self).map(*args, **kwargs) + return super().map(*args, **kwargs) @wraps(LabelledData.relabel) def relabel(self, *args, **kwargs): - return super(Dataset, self).relabel(*args, **kwargs) + return super().relabel(*args, **kwargs) @property def iloc(self): diff --git a/holoviews/plotting/plotly/callbacks.py b/holoviews/plotting/plotly/callbacks.py index 4380d83837..c9423d4bef 100644 --- a/holoviews/plotting/plotly/callbacks.py +++ b/holoviews/plotting/plotly/callbacks.py @@ -1,7 +1,5 @@ from weakref import WeakValueDictionary -from param.parameterized import add_metaclass - from ...streams import ( Stream, Selection1D, RangeXY, RangeX, RangeY, BoundsXY, BoundsX, BoundsY, SelectionXY @@ -38,8 +36,7 @@ def __call__(cls, *args, **kwargs): return inst -@add_metaclass(PlotlyCallbackMetaClass) -class PlotlyCallback: +class PlotlyCallback(metaclass=PlotlyCallbackMetaClass): def __init__(self, plot, streams, source, **params): self.plot = plot