Skip to content

Commit 6e79acf

Browse files
authored
chore: Clean up and deprecate old API (#6863)
1 parent 0373d4a commit 6e79acf

4 files changed

Lines changed: 37 additions & 32 deletions

File tree

holoviews/core/dimension.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,15 @@
3333

3434
title_format = "{name}: {val}{unit}"
3535

36-
redim = Redim # pickle compatibility - remove in 2.0
36+
37+
class redim(Redim):
38+
def __init__(self, *args, **kwargs):
39+
from ..util.warnings import deprecated
40+
41+
# exists because of pickle compatibility
42+
deprecated("1.24.0", "redim", "Redim")
43+
super().__init__(*args, **kwargs)
44+
3745

3846
if t.TYPE_CHECKING:
3947
from typing_extensions import Self

holoviews/core/ndmapping.py

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from __future__ import annotations
88

99
import typing as t
10+
from contextlib import contextmanager
1011
from itertools import cycle
1112
from operator import itemgetter
1213

@@ -36,43 +37,35 @@ def _has_split_overlays(obj) -> TypeIs[HoloMap]:
3637
return hasattr(obj, "_split_overlays")
3738

3839

39-
class item_check:
40+
@contextmanager
41+
def item_check(enabled):
4042
"""Context manager to allow creating NdMapping types without
4143
performing the usual item_checks, providing significant
4244
speedups when there are a lot of items. Should only be
4345
used when both keys and values are guaranteed to be the
4446
right type, as is the case for many internal operations.
45-
4647
"""
47-
48-
def __init__(self, enabled):
49-
self.enabled = enabled
50-
51-
def __enter__(self):
52-
self._enabled = MultiDimensionalMapping._check_items
53-
MultiDimensionalMapping._check_items = self.enabled
54-
55-
def __exit__(self, exc_type, exc_val, exc_tb):
56-
MultiDimensionalMapping._check_items = self._enabled
48+
prev = MultiDimensionalMapping._check_items
49+
try:
50+
MultiDimensionalMapping._check_items = enabled
51+
yield
52+
finally:
53+
MultiDimensionalMapping._check_items = prev
5754

5855

59-
class sorted_context:
56+
@contextmanager
57+
def sorted_context(enabled):
6058
"""Context manager to temporarily disable sorting on NdMapping
6159
types. Retains the current sort order, which can be useful as
6260
an optimization on NdMapping instances where sort=True but the
6361
items are already known to have been sorted.
64-
6562
"""
66-
67-
def __init__(self, enabled):
68-
self.enabled = enabled
69-
70-
def __enter__(self):
71-
self._enabled = MultiDimensionalMapping.sort
72-
MultiDimensionalMapping.sort = self.enabled
73-
74-
def __exit__(self, exc_type, exc_val, exc_tb):
75-
MultiDimensionalMapping.sort = self._enabled # ty:ignore[invalid-assignment]
63+
prev = MultiDimensionalMapping.sort
64+
try:
65+
MultiDimensionalMapping.sort = enabled
66+
yield
67+
finally:
68+
MultiDimensionalMapping.sort = prev # ty:ignore[invalid-assignment]
7669

7770

7871
class MultiDimensionalMapping(Dimensioned):

holoviews/core/options.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
import param
4747

4848
from ..util.warnings import HoloviewsUserWarning, warn
49-
from .accessors import Opts # noqa: F401 (clean up in 2.0)
5049
from .pprint import InfoPrinter
5150
from .tree import AttrTree
5251
from .util import group_sanitizer, label_sanitizer, sanitize_identifier
@@ -56,6 +55,17 @@
5655
from ..util.settings import OutputSettings
5756

5857

58+
def __getattr__(name):
59+
if name == "Opts":
60+
from ..util.warnings import deprecated
61+
from .accessors import Opts
62+
63+
deprecated("1.24.0", "holoviews.core.options.Opts", "holoviews.core.accessors.Opts")
64+
return Opts
65+
66+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
67+
68+
5969
def cleanup_custom_options(id, weakref=None):
6070
"""Cleans up unused custom trees if all objects referencing the
6171
custom id have been garbage collected or tree is otherwise

holoviews/core/util/__init__.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,6 @@
6060
from ..layout import AdjointLayout
6161
from ..ndmapping import UniformNdMapping
6262

63-
# Python 2 builtins
64-
basestring = str
65-
long = int
66-
unicode = str
67-
cmp = lambda a, b: (a > b) - (a < b)
68-
6963
get_keywords = operator.attrgetter("varkw")
7064

7165
anonymous_dimension_label = "_"

0 commit comments

Comments
 (0)