Repository: asdf-format/asdf

Issue:
Find suitable new location for `format_tag`
This is currently in the soon the be deprecated `asdf.types`:
https://github.com/asdf-format/asdf/blob/f726fe8a2ccaa3faf33713738510aa103836cfa3/asdf/types.py#L17-L29

It does not depend on the legacy type system and could be moved to a new location.

I've only found 1  use of this in `test_schema.py`:
https://github.com/asdf-format/asdf/blob/f726fe8a2ccaa3faf33713738510aa103836cfa3/asdf/tests/test_schema.py#L639

Discussion:

Patch:
diff --git a/CHANGES.rst b/CHANGES.rst
index c93a4760..49f9e300 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -30,6 +30,7 @@ The ASDF Standard is at v1.6.0
 - Add AsdfDeprecationWarning to asdf.types [#1401]
 - deprecate default_extensions, get_default_resolver and
   get_cached_asdf_extension_list in asdf.extension [#1409]
+- move asdf.types.format_tag to asdf.testing.helpers.format_tag [#1433]
 
 2.14.3 (2022-12-15)
 -------------------
diff --git a/asdf/_types.py b/asdf/_types.py
index 92dacc9b..a8eaa327 100644
--- a/asdf/_types.py
+++ b/asdf/_types.py
@@ -3,30 +3,28 @@ import re
 import warnings
 from copy import copy
 
+import asdf.testing.helpers
+
 from . import tagged, util
 from .exceptions import AsdfDeprecationWarning
 from .versioning import AsdfSpec, AsdfVersion
 
-__all__ = ["format_tag", "CustomType", "AsdfType", "ExtensionType"]
+__all__ = ["format_tag", "CustomType", "AsdfType", "ExtensionType"]  # noqa: F822
 
 
 # regex used to parse module name from optional version string
 MODULE_RE = re.compile(r"([a-zA-Z]+)(-(\d+\.\d+\.\d+))?")
 
 
-def format_tag(organization, standard, version, tag_name):
-    """
-    Format a YAML tag.
-    """
-    tag = f"tag:{organization}:{standard}/{tag_name}"
-
-    if version is None:
-        return tag
-
-    if isinstance(version, AsdfSpec):
-        version = str(version.spec)
-
-    return f"{tag}-{version}"
+def __getattr__(name):
+    if name == "format_tag":
+        warnings.warn(
+            "asdf.types.format_tag is deprecated. Please use asdf.testing.helpers.format_tag",
+            AsdfDeprecationWarning,
+        )
+        return asdf.testing.helpers.format_tag
+    msg = f"module {__name__!r} has no attribute {name!r}"
+    raise AttributeError(msg)
 
 
 _all_asdftypes = set()
@@ -229,7 +227,7 @@ class ExtensionType:
         -------
             `str` representing the YAML tag
         """
-        return format_tag(cls.organization, cls.standard, cls.version if versioned else None, name)
+        return asdf.testing.helpers.format_tag(cls.organization, cls.standard, cls.version if versioned else None, name)
 
     @classmethod
     def tag_base(cls):


Test patch:
diff --git a/asdf/testing/helpers.py b/asdf/testing/helpers.py
index fc30b768..0b70b2a3 100644
--- a/asdf/testing/helpers.py
+++ b/asdf/testing/helpers.py
@@ -5,6 +5,22 @@ Helpers for writing unit tests of ASDF support.
 from io import BytesIO
 
 import asdf
+from asdf.versioning import AsdfSpec
+
+
+def format_tag(organization, standard, version, tag_name):
+    """
+    Format a YAML tag.
+    """
+    tag = f"tag:{organization}:{standard}/{tag_name}"
+
+    if version is None:
+        return tag
+
+    if isinstance(version, AsdfSpec):
+        version = str(version.spec)
+
+    return f"{tag}-{version}"
 
 
 def roundtrip_object(obj, version=None):
diff --git a/asdf/tests/test_deprecated.py b/asdf/tests/test_deprecated.py
index 49746b5f..70584fac 100644
--- a/asdf/tests/test_deprecated.py
+++ b/asdf/tests/test_deprecated.py
@@ -3,7 +3,9 @@ import sys
 import pytest
 
 import asdf
+import asdf._types
 import asdf.extension
+import asdf.testing.helpers
 from asdf._types import CustomType
 from asdf.exceptions import AsdfDeprecationWarning
 from asdf.tests.helpers import assert_extension_correctness
@@ -84,3 +86,9 @@ def test_default_resolver():
 def test_get_cached_asdf_extension_list_deprecation():
     with pytest.warns(AsdfDeprecationWarning, match="get_cached_asdf_extension_list is deprecated"):
         asdf.extension.get_cached_asdf_extension_list([])
+
+
+def test_asdf_type_format_tag():
+    with pytest.warns(AsdfDeprecationWarning, match="asdf.types.format_tag is deprecated"):
+        asdf._types.format_tag
+    asdf.testing.helpers.format_tag
diff --git a/asdf/tests/test_schema.py b/asdf/tests/test_schema.py
index bfc467bb..d861d5e9 100644
--- a/asdf/tests/test_schema.py
+++ b/asdf/tests/test_schema.py
@@ -7,6 +7,7 @@ from jsonschema import ValidationError
 from numpy.testing import assert_array_equal
 
 import asdf
+import asdf.testing.helpers
 from asdf import _resolver as resolver
 from asdf import _types as types
 from asdf import config_context, constants, extension, get_config, schema, tagged, util, yamlutil
@@ -640,7 +641,7 @@ def test_schema_resolved_via_entry_points():
     """Test that entry points mappings to core schema works"""
     with pytest.warns(AsdfDeprecationWarning, match="get_default_resolver is deprecated"):
         r = extension.get_default_resolver()
-    tag = types.format_tag("stsci.edu", "asdf", "1.0.0", "fits/fits")
+    tag = asdf.testing.helpers.format_tag("stsci.edu", "asdf", "1.0.0", "fits/fits")
     with pytest.warns(AsdfDeprecationWarning, match="default_extensions is deprecated"):
         url = extension.default_extensions.extension_list.tag_mapping(tag)