From 629ab96079ce961c133ee32a88624ab4e4e0b5b4 Mon Sep 17 00:00:00 2001 From: Brett Date: Wed, 15 Nov 2023 17:15:20 -0500 Subject: [PATCH] deprecate is_primitive --- asdf/_tests/test_deprecated.py | 5 +++++ asdf/_tests/test_util.py | 10 ++++++---- asdf/util.py | 14 +++++++------- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/asdf/_tests/test_deprecated.py b/asdf/_tests/test_deprecated.py index cae5e9987..3c4687090 100644 --- a/asdf/_tests/test_deprecated.py +++ b/asdf/_tests/test_deprecated.py @@ -50,3 +50,8 @@ def test_resolve_and_inline_deprecation(): with pytest.warns(AsdfDeprecationWarning, match="resolve_and_inline is deprecated"): af = asdf.AsdfFile({"arr": np.arange(42)}) af.resolve_and_inline() + + +def test_asdf_util_is_primitive_deprecation(): + with pytest.warns(AsdfDeprecationWarning, match="asdf.util.is_primitive is deprecated"): + asdf.util.is_primitive(1) diff --git a/asdf/_tests/test_util.py b/asdf/_tests/test_util.py index a0830b61d..e7c6345de 100644 --- a/asdf/_tests/test_util.py +++ b/asdf/_tests/test_util.py @@ -8,11 +8,13 @@ def test_is_primitive(): - for value in [None, "foo", 1, 1.39, 1 + 1j, True]: - assert util.is_primitive(value) is True + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", "asdf.util.is_primitive is deprecated", AsdfDeprecationWarning) + for value in [None, "foo", 1, 1.39, 1 + 1j, True]: + assert util.is_primitive(value) is True - for value in [[], (), {}, set()]: - assert util.is_primitive(value) is False + for value in [[], (), {}, set()]: + assert util.is_primitive(value) is False def test_not_set(): diff --git a/asdf/util.py b/asdf/util.py index 36cafd3ed..6029fbe8c 100644 --- a/asdf/util.py +++ b/asdf/util.py @@ -20,8 +20,7 @@ from importlib_metadata import packages_distributions from packaging.version import Version -from . import constants -from .exceptions import AsdfDeprecationWarning +from . import constants, exceptions # We're importing our own copy of urllib.parse because # we need to patch it to support asdf:// URIs, but it'd @@ -78,7 +77,7 @@ def human_list(line, separator="and"): >>> human_list(["vanilla", "strawberry", "chocolate"], "or") # doctest: +SKIP 'vanilla, strawberry or chocolate' """ - warnings.warn("asdf.util.human_list is deprecated", AsdfDeprecationWarning) + warnings.warn("asdf.util.human_list is deprecated", exceptions.AsdfDeprecationWarning) if len(line) == 1: return line[0] @@ -126,7 +125,7 @@ def iter_subclasses(cls): """ Returns all subclasses of a class. """ - warnings.warn("asdf.util.iter_subclasses is deprecated", AsdfDeprecationWarning) + warnings.warn("asdf.util.iter_subclasses is deprecated", exceptions.AsdfDeprecationWarning) yield from _iter_subclasses(cls) @@ -289,7 +288,7 @@ def resolve_name(name): If the module or named object is not found. """ - warnings.warn("asdf.util.resolve_name is deprecated, see astropy.utils.resolve_name", AsdfDeprecationWarning) + warnings.warn("asdf.util.resolve_name is deprecated, see astropy.utils.resolve_name", exceptions.AsdfDeprecationWarning) # Note: On python 2 these must be str objects and not unicode parts = [str(part) for part in name.split(".")] @@ -366,7 +365,7 @@ def minversion(module, version, inclusive=True): as opposed to strictly greater than (default: `True`). """ - warnings.warn("asdf.util.minversion is deprecated, see astropy.utils.minversion", AsdfDeprecationWarning) + warnings.warn("asdf.util.minversion is deprecated, see astropy.utils.minversion", exceptions.AsdfDeprecationWarning) if isinstance(module, types.ModuleType): module_name = module.__name__ @@ -376,7 +375,7 @@ def minversion(module, version, inclusive=True): module_version = None try: with warnings.catch_warnings(): - warnings.filterwarnings("ignore", "asdf.util.resolve_name", AsdfDeprecationWarning) + warnings.filterwarnings("ignore", "asdf.util.resolve_name", exceptions.AsdfDeprecationWarning) module = resolve_name(module_name) except ImportError: return False @@ -468,6 +467,7 @@ def is_primitive(value): bool True if the value is primitive, False otherwise """ + warnings.warn("asdf.util.is_primitive is deprecated", exceptions.AsdfDeprecationWarning) return isinstance(value, (bool, int, float, complex, str)) or value is None