# ══════════════════════════════════════════════════════════════════════════
# ___ ___ ___ _ _ ___
# / _ \ / __|_ ) | | /_\ | _ )
# | (_) | (__ / / | |__ / _ \| _ \
# \__\_\\___/___| |____/_/ \_\___/
#
# QC2 @ CHALMERS CALIBRATION TOOLKIT
# (c) 2026 Chalmers University of Technology and Project Contributors
# ──────────────────────────────────────────────────────────────────────────
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ──────────────────────────────────────────────────────────────────────────
# CONTRIBUTORS list:
#
# Axel Andersson, axean@chalmers.se
# ══════════════════════════════════════════════════════════════════════════
import functools
import warnings
from collections.abc import Callable
from typing import TypeVar
_F = TypeVar("_F", bound=Callable)
[docs]
def deprecated(replacement: str) -> Callable[[_F], _F]:
"""Mark a callable or class as deprecated, pointing callers to *replacement*."""
def decorator(obj: _F) -> _F:
if isinstance(obj, type):
original_init = obj.__init__
@functools.wraps(original_init)
def __init__(self, *args, **kwargs):
warnings.warn(
f"{obj.__name__} is deprecated, use {replacement} instead.",
FutureWarning,
stacklevel=2,
)
original_init(self, *args, **kwargs)
return type(
obj.__name__, (obj,), {"__init__": __init__, "__doc__": obj.__doc__}
)
@functools.wraps(obj)
def wrapper(*args, **kwargs):
warnings.warn(
f"{obj.__name__} is deprecated, use {replacement} instead.",
FutureWarning,
stacklevel=2,
)
return obj(*args, **kwargs)
return wrapper
return decorator