From 93d8c1cd19f079be621bdc9a27ac72d2aaa0754b Mon Sep 17 00:00:00 2001 From: gmuloc Date: Wed, 5 Mar 2025 16:59:08 +0100 Subject: [PATCH] chore(anta): Add deprecation on deprecated method --- anta/catalog.py | 15 ++++----------- anta/result_manager/__init__.py | 4 ++++ pyproject.toml | 3 ++- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/anta/catalog.py b/anta/catalog.py index 0aeebd91c..f4b7c82d9 100644 --- a/anta/catalog.py +++ b/anta/catalog.py @@ -14,11 +14,11 @@ from json import load as json_load from pathlib import Path from typing import TYPE_CHECKING, Any, Literal, Optional, Union -from warnings import warn from pydantic import BaseModel, ConfigDict, RootModel, ValidationError, ValidationInfo, field_validator, model_serializer, model_validator from pydantic.types import ImportString from pydantic_core import PydanticCustomError +from typing_extensions import deprecated from yaml import YAMLError, safe_dump, safe_load from anta.logger import anta_log_exception @@ -440,13 +440,12 @@ def merge_catalogs(cls, catalogs: list[AntaCatalog]) -> AntaCatalog: combined_tests = list(chain(*(catalog.tests for catalog in catalogs))) return cls(tests=combined_tests) + @deprecated( + "This method is deprecated, use `AntaCatalogs.merge_catalogs` class method instead. This will be removed in ANTA v2.0.0.", category=DeprecationWarning + ) def merge(self, catalog: AntaCatalog) -> AntaCatalog: """Merge two AntaCatalog instances. - Warning - ------- - This method is deprecated and will be removed in ANTA v2.0. Use `AntaCatalog.merge_catalogs()` instead. - Parameters ---------- catalog @@ -457,12 +456,6 @@ def merge(self, catalog: AntaCatalog) -> AntaCatalog: AntaCatalog A new AntaCatalog instance containing the tests of the two instances. """ - # TODO: Use a decorator to deprecate this method instead. See https://github.com/aristanetworks/anta/issues/754 - warn( - message="AntaCatalog.merge() is deprecated and will be removed in ANTA v2.0. Use AntaCatalog.merge_catalogs() instead.", - category=DeprecationWarning, - stacklevel=2, - ) return self.merge_catalogs([self, catalog]) def dump(self) -> AntaCatalogFile: diff --git a/anta/result_manager/__init__.py b/anta/result_manager/__init__.py index d0a348861..39ed3644a 100644 --- a/anta/result_manager/__init__.py +++ b/anta/result_manager/__init__.py @@ -316,6 +316,7 @@ def filter(self, hide: set[AntaTestStatus]) -> ResultManager: manager.results = self.get_results(possible_statuses - hide) return manager + @deprecated("This method is deprecated. This will be removed in ANTA v2.0.0.", category=DeprecationWarning) def filter_by_tests(self, tests: set[str]) -> ResultManager: """Get a filtered ResultManager that only contains specific tests. @@ -333,6 +334,7 @@ def filter_by_tests(self, tests: set[str]) -> ResultManager: manager.results = [result for result in self._result_entries if result.test in tests] return manager + @deprecated("This method is deprecated. This will be removed in ANTA v2.0.0.", category=DeprecationWarning) def filter_by_devices(self, devices: set[str]) -> ResultManager: """Get a filtered ResultManager that only contains specific devices. @@ -350,6 +352,7 @@ def filter_by_devices(self, devices: set[str]) -> ResultManager: manager.results = [result for result in self._result_entries if result.name in devices] return manager + @deprecated("This method is deprecated. This will be removed in ANTA v2.0.0.", category=DeprecationWarning) def get_tests(self) -> set[str]: """Get the set of all the test names. @@ -360,6 +363,7 @@ def get_tests(self) -> set[str]: """ return {str(result.test) for result in self._result_entries} + @deprecated("This method is deprecated. This will be removed in ANTA v2.0.0.", category=DeprecationWarning) def get_devices(self) -> set[str]: """Get the set of all the device names. diff --git a/pyproject.toml b/pyproject.toml index 4c37604e9..cedb98215 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,7 +28,8 @@ dependencies = [ "pydantic-extra-types>=2.3.0", "PyYAML>=6.0", "requests>=2.31.0", - "rich>=13.5.2,<14" + "rich>=13.5.2,<14", + "typing_extensions>=4.12" # required for deprecated before Python 3.13 ] keywords = ["test", "anta", "Arista", "network", "automation", "networking", "devops", "netdevops"] classifiers = [