Skip to content

Commit

Permalink
deprecate is_primitive
Browse files Browse the repository at this point in the history
  • Loading branch information
braingram committed Nov 15, 2023
1 parent 1073236 commit 30c54ff
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
6 changes: 6 additions & 0 deletions asdf/_tests/test_deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import pytest

import asdf
from asdf.exceptions import AsdfDeprecationWarning


Expand All @@ -15,3 +16,8 @@ def test_asdf_stream_deprecation():
def test_asdf_asdf_SerializationContext_import_deprecation():
with pytest.warns(AsdfDeprecationWarning, match="importing SerializationContext from asdf.asdf"):
from asdf.asdf import SerializationContext # noqa: F401


def test_asdf_util_is_primitive_deprecation():
with pytest.warns(AsdfDeprecationWarning, match="asdf.util.is_primitive is deprecated"):
asdf.util.is_primitive(1)
12 changes: 8 additions & 4 deletions asdf/_tests/test_util.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import io
import warnings

import pytest

from asdf import generic_io, util
from asdf.exceptions import AsdfDeprecationWarning


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():
Expand Down
4 changes: 3 additions & 1 deletion asdf/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import re
import struct
import types
import warnings
from functools import lru_cache
from importlib import metadata
from urllib.request import pathname2url
Expand All @@ -19,7 +20,7 @@
from importlib_metadata import packages_distributions
from packaging.version import Version

from . import constants
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
Expand Down Expand Up @@ -449,6 +450,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


Expand Down

0 comments on commit 30c54ff

Please sign in to comment.