From a78363364ae717a76a03edd1903025c7aae4c601 Mon Sep 17 00:00:00 2001 From: Brett Date: Mon, 28 Oct 2024 16:48:47 -0400 Subject: [PATCH 1/2] only error if Converter.select_tag isn't implemented for a multi-tag converter --- asdf/_tests/test_extension.py | 6 ++---- asdf/extension/_converter.py | 21 ++------------------- 2 files changed, 4 insertions(+), 23 deletions(-) diff --git a/asdf/_tests/test_extension.py b/asdf/_tests/test_extension.py index f9b8baf50..d9a16c54d 100644 --- a/asdf/_tests/test_extension.py +++ b/asdf/_tests/test_extension.py @@ -6,7 +6,7 @@ import asdf from asdf import AsdfFile, config_context -from asdf.exceptions import AsdfManifestURIMismatchWarning, AsdfSerializationError, AsdfWarning, ValidationError +from asdf.exceptions import AsdfManifestURIMismatchWarning, AsdfSerializationError, ValidationError from asdf.extension import ( Compressor, Converter, @@ -892,10 +892,8 @@ def from_yaml_tree(self, node, tag, ctx): "asdf://somewhere.org/tags/foo-2.0.0", ] extension = FullExtension(converters=[FooConverter()], tags=tags) - ctx_type = pytest.warns if is_subclass else pytest.raises - exception_class = AsdfWarning if is_subclass else RuntimeError with config_context() as config: - with ctx_type(exception_class, match="Converter handles multiple tags"): + with pytest.raises(RuntimeError, match="Converter handles multiple tags"): config.add_extension(extension) diff --git a/asdf/extension/_converter.py b/asdf/extension/_converter.py index fca64a936..5e9835625 100644 --- a/asdf/extension/_converter.py +++ b/asdf/extension/_converter.py @@ -4,9 +4,7 @@ """ import abc -import warnings -from asdf.exceptions import AsdfWarning from asdf.util import get_class_name, uri_match @@ -179,23 +177,8 @@ def __init__(self, delegate, extension): raise TypeError(msg) if len(relevant_tags) > 1 and not hasattr(delegate, "select_tag"): - # we cannot use isinstance here because Converter supports - # virtual subclasses - if Converter in delegate.__class__.__mro__: - # prior to asdf 3.0 Converter provided a default select_tag - # to provide backwards compatibility allow Converter subclasses - # to be registered with >1 tag but produce a warning - msg = ( - "Converter handles multiple tags for this extension, " - "but does not implement a select_tag method. " - "This previously worked because Converter subclasses inherited " - "the now removed select_tag. This will be an error in a future " - "version of asdf" - ) - warnings.warn(msg, AsdfWarning) - else: - msg = "Converter handles multiple tags for this extension, but does not implement a select_tag method." - raise RuntimeError(msg) + msg = "Converter handles multiple tags for this extension, but does not implement a select_tag method." + raise RuntimeError(msg) self._tags = sorted(relevant_tags) From 583034ea25ec71eb20ab3b2750d851fdd8b1ef40 Mon Sep 17 00:00:00 2001 From: Brett Date: Mon, 28 Oct 2024 16:51:56 -0400 Subject: [PATCH 2/2] add changelog fragment --- changes/1853.feature.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 changes/1853.feature.rst diff --git a/changes/1853.feature.rst b/changes/1853.feature.rst new file mode 100644 index 000000000..f5817ef2c --- /dev/null +++ b/changes/1853.feature.rst @@ -0,0 +1 @@ +Raise RuntimeError if a Convert subclass supports multiple tags but doesn't implement select_tag.