From d34e126408cd4fe18499a51751c4723cd122f276 Mon Sep 17 00:00:00 2001 From: Jim Bosch Date: Mon, 6 Nov 2023 12:34:34 -0500 Subject: [PATCH] DO NOT MERGE: convert deprecation warnings into errors --- .../lsst/daf/butler/dimensions/_coordinate.py | 62 +++++++++---------- .../dimensions/_data_coordinate_iterable.py | 9 +-- python/lsst/daf/butler/dimensions/_graph.py | 41 +++++------- .../lsst/daf/butler/dimensions/_universe.py | 3 + .../daf/butler/registry/queries/_results.py | 1 + 5 files changed, 49 insertions(+), 67 deletions(-) diff --git a/python/lsst/daf/butler/dimensions/_coordinate.py b/python/lsst/daf/butler/dimensions/_coordinate.py index b7c9ef428c..3a57d0c0ac 100644 --- a/python/lsst/daf/butler/dimensions/_coordinate.py +++ b/python/lsst/daf/butler/dimensions/_coordinate.py @@ -35,7 +35,6 @@ __all__ = ("DataCoordinate", "DataId", "DataIdKey", "DataIdValue", "SerializedDataCoordinate") import numbers -import warnings from abc import abstractmethod from collections.abc import Iterable, Iterator, Mapping, Set from typing import TYPE_CHECKING, Any, ClassVar, Literal, cast, overload @@ -43,7 +42,6 @@ from deprecated.sphinx import deprecated from lsst.daf.butler._compat import _BaseModelCompat from lsst.sphgeom import IntersectionRegion, Region -from lsst.utils.introspection import find_outside_stacklevel from .._named import NamedKeyMapping, NamedValueAbstractSet, NameLookupMapping from .._timespan import Timespan @@ -216,13 +214,10 @@ def standardize( ) if graph is not None: # TODO: remove argument on DM-41326. - warnings.warn( + raise FutureWarning( "The 'graph' argument to DataCoordinate.standardize is deprecated in favor of the " - "'dimensions' argument, and will be removed after v27.", - category=FutureWarning, - stacklevel=find_outside_stacklevel("lsst.daf.butler"), + "'dimensions' argument, and will be removed after v27." ) - dimensions = graph.names if dimensions is not None: dimensions = universe.conform(dimensions) del graph # make sure we don't actualy use this below @@ -243,13 +238,10 @@ def standardize( if mapping.hasFull(): new_mapping.update((name, mapping[name]) for name in mapping.dimensions.implied) elif isinstance(mapping, NamedKeyMapping): - warnings.warn( + raise FutureWarning( "Passing a NamedKeyMapping to DataCoordinate.standardize is deprecated, and will be " - "removed after v27.", - category=FutureWarning, - stacklevel=find_outside_stacklevel("lsst.daf.butler"), + "removed after v27." ) - new_mapping.update(mapping.byName()) elif mapping is not None: new_mapping.update(mapping) new_mapping.update(kwargs) @@ -346,6 +338,7 @@ def makeEmpty(universe: DimensionUniverse) -> DataCoordinate: "removed after v27.", version="v27", category=FutureWarning, + action="error", ) def fromRequiredValues(graph: DimensionGraph, values: tuple[DataIdValue, ...]) -> DataCoordinate: """Construct a `DataCoordinate` from required dimension values. @@ -411,6 +404,7 @@ def from_required_values(dimensions: DimensionGroup, values: tuple[DataIdValue, "removed after v27.", version="v27", category=FutureWarning, + action="error", ) def fromFullValues(graph: DimensionGraph, values: tuple[DataIdValue, ...]) -> DataCoordinate: """Construct a `DataCoordinate` from all dimension values. @@ -497,6 +491,7 @@ def __lt__(self, other: Any) -> bool: ".mapping and .required attributes, and will be dropped after v27.", version="v27", category=FutureWarning, + action="error", ) def __iter__(self) -> Iterator[Dimension]: return iter(self.keys()) @@ -507,6 +502,7 @@ def __iter__(self) -> Iterator[Dimension]: ".mapping and .required attributes, and will be dropped after v27.", version="v27", category=FutureWarning, + action="error", ) def __len__(self) -> int: return len(self.keys()) @@ -517,6 +513,7 @@ def __len__(self) -> int: ".mapping and .required attributes, and will be dropped after v27.", version="v27", category=FutureWarning, + action="error", ) def keys(self) -> NamedValueAbstractSet[Dimension]: # type: ignore return self.graph.required @@ -528,6 +525,7 @@ def keys(self) -> NamedValueAbstractSet[Dimension]: # type: ignore "attribute, and will be dropped after v27.", version="v27", category=FutureWarning, + action="error", ) def names(self) -> Set[str]: """Names of the required dimensions identified by this data ID. @@ -655,6 +653,7 @@ def dimensions(self) -> DimensionGroup: "DataCoordinate.graph is deprecated in favor of .dimensions, and will be dropped after v27.", version="v27", category=FutureWarning, + action="error", ) def graph(self) -> DimensionGraph: """Dimensions identified by this data ID (`DimensionGraph`). @@ -687,6 +686,7 @@ def hasFull(self) -> bool: "DataCoordinate.full is deprecated in favor of .mapping, and will be dropped after v27.", version="v27", category=FutureWarning, + action="error", ) @abstractmethod def full(self) -> NamedKeyMapping[Dimension, DataIdValue]: @@ -708,6 +708,7 @@ def full(self) -> NamedKeyMapping[Dimension, DataIdValue]: "after v27.", version="v27", category=FutureWarning, + action="error", ) def values_tuple(self) -> tuple[DataIdValue, ...]: """Return the required values (only) of this data ID as a tuple. @@ -844,6 +845,7 @@ def pack(self, name: str, *, returnMaxBits: Literal[False]) -> int: "Deprecated in favor of configurable dimension packers. Will be removed after v26.", version="v26", category=FutureWarning, + action="error", ) def pack(self, name: str, *, returnMaxBits: bool = False) -> tuple[int, int] | int: """Pack this data ID into an integer. @@ -1026,12 +1028,9 @@ def __str__(self) -> str: def __getitem__(self, key: DimensionElement | str) -> DimensionRecord | None: if isinstance(key, DimensionElement): - warnings.warn( - "Using Dimension keys in DataCoordinate is deprecated and will not be supported after v27.", - category=FutureWarning, - stacklevel=find_outside_stacklevel("lsst.daf.butler"), + raise FutureWarning( + "Using Dimension keys in DataCoordinate is deprecated and will not be supported after v27." ) - key = key.name return self._target._record(key) # TODO: fix on DM-41326. @@ -1040,6 +1039,7 @@ def __getitem__(self, key: DimensionElement | str) -> DimensionRecord | None: "v27. Use DataCoordinate.dimensions.elements to get the names of all dimension elements instead.", version="v27", category=FutureWarning, + action="error", ) def __iter__(self) -> Iterator[DimensionElement]: return iter(self.keys()) @@ -1058,6 +1058,7 @@ def keys(self) -> NamedValueAbstractSet[DimensionElement]: # type: ignore "will be removed after v27.", version="v27", category=FutureWarning, + action="error", ) def names(self) -> Set[str]: # Docstring inherited from `NamedKeyMapping`. @@ -1103,12 +1104,9 @@ def __getitem__(self, key: DataIdKey) -> DataIdValue: # Docstring inherited from DataCoordinate. # TODO: remove on DM-41326. if isinstance(key, Dimension): - warnings.warn( - "Using Dimension keys in DataCoordinate is deprecated and will not be supported after v27.", - category=FutureWarning, - stacklevel=find_outside_stacklevel("lsst.daf.butler"), + raise FutureWarning( + "Using Dimension keys in DataCoordinate is deprecated and will not be supported after v27." ) - key = key.name index = self._dimensions._data_coordinate_indices[key] try: return self._values[index] @@ -1124,6 +1122,7 @@ def __getitem__(self, key: DataIdKey) -> DataIdValue: "Use `dict(data_id.required)` as an exact replacement for `data_id.byName()`.", version="v27", category=FutureWarning, + action="error", ) def byName(self) -> dict[str, DataIdValue]: # Docstring inheritance. @@ -1265,10 +1264,8 @@ def expanded( for d in self._dimensions.implied ) if isinstance(records, NamedKeyMapping): - warnings.warn( - "NamedKeyMappings will not be accepted after v27; pass a Mapping with str keys instead.", - stacklevel=find_outside_stacklevel("lsst.daf.butler"), - category=FutureWarning, + raise FutureWarning( + "NamedKeyMappings will not be accepted after v27; pass a Mapping with str keys instead." ) return _ExpandedTupleDataCoordinate(self._dimensions, values, records) @@ -1335,6 +1332,7 @@ def union(self, other: DataCoordinate) -> DataCoordinate: "DataCoordinate.full is deprecated in favor of .mapping, and will be dropped after v27.", version="v27", category=FutureWarning, + action="error", ) def full(self) -> NamedKeyMapping[Dimension, DataIdValue]: # Docstring inherited. @@ -1345,10 +1343,8 @@ def expanded( ) -> DataCoordinate: # Docstring inherited from DataCoordinate if isinstance(records, NamedKeyMapping): - warnings.warn( - "NamedKeyMappings will not be accepted after v27; pass a Mapping with str keys instead.", - stacklevel=find_outside_stacklevel("lsst.daf.butler"), - category=FutureWarning, + raise FutureWarning( + "NamedKeyMappings will not be accepted after v27; pass a Mapping with str keys instead." ) return _ExpandedTupleDataCoordinate(self._dimensions, self._values, records) @@ -1406,10 +1402,8 @@ def expanded( ) -> DataCoordinate: # Docstring inherited from DataCoordinate. if isinstance(records, NamedKeyMapping): - warnings.warn( - "NamedKeyMappings will not be accepted after v27; pass a Mapping with str keys instead.", - stacklevel=find_outside_stacklevel("lsst.daf.butler"), - category=FutureWarning, + raise FutureWarning( + "NamedKeyMappings will not be accepted after v27; pass a Mapping with str keys instead." ) return self diff --git a/python/lsst/daf/butler/dimensions/_data_coordinate_iterable.py b/python/lsst/daf/butler/dimensions/_data_coordinate_iterable.py index 72d8c19d62..96272c1fdc 100644 --- a/python/lsst/daf/butler/dimensions/_data_coordinate_iterable.py +++ b/python/lsst/daf/butler/dimensions/_data_coordinate_iterable.py @@ -33,13 +33,11 @@ "DataCoordinateSequence", ) -import warnings from abc import abstractmethod from collections.abc import Collection, Iterable, Iterator, Sequence, Set from typing import Any, overload from deprecated.sphinx import deprecated -from lsst.utils.introspection import find_outside_stacklevel from ._coordinate import DataCoordinate from ._graph import DimensionGraph @@ -84,6 +82,7 @@ def fromScalar(dataId: DataCoordinate) -> _ScalarDataCoordinateIterable: "Deprecated in favor of .dimensions; will be removed after v26.", category=FutureWarning, version="v27", + action="error", ) def graph(self) -> DimensionGraph: """Dimensions identified by these data IDs (`DimensionGraph`).""" @@ -312,12 +311,10 @@ def __init__( "universe must be provided, either directly or via dimensions, dataIds, or graph." ) if graph is not None: - warnings.warn( + raise FutureWarning( "The 'graph' argument to DataCoordinateIterable constructors is deprecated in favor of " " passing an iterable of dimension names as the 'dimensions' argument, and wil be removed " - "after v27.", - stacklevel=find_outside_stacklevel("lsst.daf.butler"), - category=FutureWarning, + "after v27." ) if dimensions is not None: dimensions = universe.conform(dimensions) diff --git a/python/lsst/daf/butler/dimensions/_graph.py b/python/lsst/daf/butler/dimensions/_graph.py index 1142e2a908..4e3fb29e25 100644 --- a/python/lsst/daf/butler/dimensions/_graph.py +++ b/python/lsst/daf/butler/dimensions/_graph.py @@ -29,14 +29,12 @@ __all__ = ["DimensionGraph", "SerializedDimensionGraph"] -import warnings from collections.abc import Iterable, Iterator, Mapping, Set from typing import TYPE_CHECKING, Any, ClassVar, TypeVar, cast from deprecated.sphinx import deprecated from lsst.daf.butler._compat import _BaseModelCompat from lsst.utils.classes import cached_getter, immutable -from lsst.utils.introspection import find_outside_stacklevel from .._named import NamedValueAbstractSet, NameMappingSetView from .._topology import TopologicalFamily, TopologicalSpace @@ -90,6 +88,7 @@ def __init__(self, keys: Set[str], universe: DimensionUniverse): + "Use a dict comprehension and DimensionUniverse indexing to construct a mapping when needed.", version="v27", category=FutureWarning, + action="error", ) def asMapping(self) -> Mapping[str, _T]: return super().asMapping() @@ -99,6 +98,7 @@ def asMapping(self) -> Mapping[str, _T]: _NVAS_DEPRECATION_MSG + "Use DimensionUniverse for DimensionElement lookups.", version="v27", category=FutureWarning, + action="error", ) def __getitem__(self, key: str | _T) -> _T: return super().__getitem__(key) @@ -107,64 +107,48 @@ def __contains__(self, key: Any) -> bool: from ._elements import DimensionElement if isinstance(key, DimensionElement): - warnings.warn( - _NVAS_DEPRECATION_MSG + "'in' expressions must use str keys.", - category=FutureWarning, - stacklevel=find_outside_stacklevel("lsst.daf.butler."), - ) + raise FutureWarning(_NVAS_DEPRECATION_MSG + "'in' expressions must use str keys.") return super().__contains__(key) def __iter__(self) -> Iterator[_T]: # TODO: Remove on DM-41326. - warnings.warn( + raise FutureWarning( _NVAS_DEPRECATION_MSG + ( "In the future, iteration will yield str names; for now, use .names " "to do the same without triggering this warning." - ), - category=FutureWarning, - stacklevel=find_outside_stacklevel("lsst.daf.butler."), + ) ) - return super().__iter__() def __eq__(self, other: Any) -> bool: # TODO: Remove on DM-41326. - warnings.warn( + raise FutureWarning( _NVAS_DEPRECATION_MSG + ( "In the future, set-equality will assume str keys; for now, use .names " "to do the same without triggering this warning." - ), - category=FutureWarning, - stacklevel=find_outside_stacklevel("lsst.daf.butler."), + ) ) - return super().__eq__(other) def __le__(self, other: Set[Any]) -> bool: # TODO: Remove on DM-41326. - warnings.warn( + raise FutureWarning( _NVAS_DEPRECATION_MSG + ( "In the future, subset tests will assume str keys; for now, use .names " "to do the same without triggering this warning." - ), - category=FutureWarning, - stacklevel=find_outside_stacklevel("lsst.daf.butler."), + ) ) - return super().__le__(other) def __ge__(self, other: Set[Any]) -> bool: # TODO: Remove on DM-41326. - warnings.warn( + raise FutureWarning( _NVAS_DEPRECATION_MSG + ( "In the future, superset tests will assume str keys; for now, use .names " "to do the same without triggering this warning." - ), - category=FutureWarning, - stacklevel=find_outside_stacklevel("lsst.daf.butler."), + ) ) - return super().__ge__(other) # TODO: Remove on DM-41326. @@ -172,6 +156,7 @@ def __ge__(self, other: Set[Any]) -> bool: "DimensionGraph is deprecated in favor of DimensionGroup and will be removed after v27.", category=FutureWarning, version="v27", + action="error", ) @immutable class DimensionGraph: @@ -500,6 +485,7 @@ def __and__(self, other: DimensionGroup | DimensionGraph) -> DimensionGraph: "use .lookup_order. DimensionGraph will be removed after v27.", category=FutureWarning, version="v27", + action="error", ) def primaryKeyTraversalOrder(self) -> tuple[DimensionElement, ...]: """A tuple of all elements in specific order. @@ -531,6 +517,7 @@ def temporal(self) -> NamedValueAbstractSet[TopologicalFamily]: "use .spatial or .temporal. DimensionGraph will be removed after v27.", category=FutureWarning, version="v27", + action="error", ) def topology(self) -> Mapping[TopologicalSpace, NamedValueAbstractSet[TopologicalFamily]]: """Families of elements in this graph that can participate in diff --git a/python/lsst/daf/butler/dimensions/_universe.py b/python/lsst/daf/butler/dimensions/_universe.py index db7fdc9c32..b226a0179b 100644 --- a/python/lsst/daf/butler/dimensions/_universe.py +++ b/python/lsst/daf/butler/dimensions/_universe.py @@ -423,6 +423,7 @@ def getDimensionIndex(self, name: str) -> int: "Deprecated in favor of DimensionUniverse.conform, and will be removed after v27.", version="v27", category=FutureWarning, + action="error", ) def expandDimensionNameSet(self, names: set[str]) -> None: """Expand a set of dimension names in-place. @@ -459,6 +460,7 @@ def expandDimensionNameSet(self, names: set[str]) -> None: "and DimensionGroup, and will be removed after v27.", version="v27", category=FutureWarning, + action="error", ) def extract(self, iterable: Iterable[Dimension | str]) -> DimensionGraph: """Construct graph from iterable. @@ -563,6 +565,7 @@ def sorted(self, elements: Iterable[Any], *, reverse: bool = False) -> list[Any] "Deprecated in favor of configurable dimension packers. Will be removed after v26.", version="v26", category=FutureWarning, + action="error", ) def makePacker(self, name: str, dataId: DataCoordinate) -> DimensionPacker: """Make a dimension packer. diff --git a/python/lsst/daf/butler/registry/queries/_results.py b/python/lsst/daf/butler/registry/queries/_results.py index 6316423edf..893d1a53e3 100644 --- a/python/lsst/daf/butler/registry/queries/_results.py +++ b/python/lsst/daf/butler/registry/queries/_results.py @@ -90,6 +90,7 @@ def __repr__(self) -> str: "Deprecated in favor of .dimensions. Will be removed after v27.", version="v27", category=FutureWarning, + action="error", ) def graph(self) -> DimensionGraph: # Docstring inherited from DataCoordinateIterable.