Skip to content

Commit

Permalink
Restore TagDefinition.schema_uri property but add deprecation warning
Browse files Browse the repository at this point in the history
  • Loading branch information
Ed Slavich committed Feb 2, 2022
1 parent 6fbc09c commit 3bd825c
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
not been run. [#1057]

- Add ability for tags to correspond to multiple schema_uri, with an
implied allOf among the schema_uris. [#1058]
implied allOf among the schema_uris. [#1058, #1069]

- Add the URI of the file being parsed to ``SerializationContext``. [#1065]

Expand Down
33 changes: 31 additions & 2 deletions asdf/extension/_tag.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import warnings

from asdf.exceptions import AsdfDeprecationWarning


class TagDefinition:
"""
Container for properties of a custom YAML tag.
Expand Down Expand Up @@ -43,15 +48,39 @@ def tag_uri(self):
return self._tag_uri

@property
def schema_uris(self):
def schema_uri(self):
"""
DEPRECATED
Get the URI of the schema that should be used to validate
objects wtih this tag.
objects with this tag.
Returns
-------
str or None
"""
warnings.warn(
"The TagDefinition.schema_uri property is deprecated. Use TagDefinition.schema_uris instead.",
AsdfDeprecationWarning
)

if len(self._schema_uris) == 0:
return None
elif len(self._schema_uris) == 1:
return self._schema_uris[0]
else:
raise RuntimeError("Cannot use TagDefinition.schema_uri when multiple schema URIs are present")

@property
def schema_uris(self):
"""
Get the URIs of the schemas that should be used to validate
objects with this tag.
Returns
-------
list
"""
return self._schema_uris

@property
Expand Down
16 changes: 16 additions & 0 deletions asdf/tests/test_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
)

from asdf import config_context
from asdf.exceptions import AsdfDeprecationWarning
from asdf.types import CustomType

from asdf.tests.helpers import assert_extension_correctness
Expand Down Expand Up @@ -437,6 +438,21 @@ def test_tag_definition():

assert "URI: asdf://somewhere.org/extensions/foo/tags/foo-1.0" in repr(tag_def)

with pytest.warns(DeprecationWarning):
assert tag_def.schema_uri == "asdf://somewhere.org/extensions/foo/schemas/foo-1.0"

tag_def = TagDefinition(
"asdf://somewhere.org/extensions/foo/tags/foo-1.0",
schema_uris=["asdf://somewhere.org/extensions/foo/schemas/foo-1.0", "asdf://somewhere.org/extensions/foo/schemas/base-1.0"],
title="Some title",
description="Some description",
)

assert tag_def.schema_uris == ["asdf://somewhere.org/extensions/foo/schemas/foo-1.0", "asdf://somewhere.org/extensions/foo/schemas/base-1.0"]
with pytest.warns(DeprecationWarning):
with pytest.raises(RuntimeError):
tag_def.schema_uri

with pytest.raises(ValueError):
TagDefinition("asdf://somewhere.org/extensions/foo/tags/foo-*")

Expand Down

0 comments on commit 3bd825c

Please sign in to comment.