diff --git a/asdf/_tests/test_extension.py b/asdf/_tests/test_extension.py index c45125d5a..5f5559712 100644 --- a/asdf/_tests/test_extension.py +++ b/asdf/_tests/test_extension.py @@ -913,11 +913,14 @@ def from_yaml_tree(self, node, tag, ctx): roundtrip_object(obj) -def test_warning_for_default_select_tag(): +@pytest.mark.parametrize("is_subclass", [True, False]) +def test_warning_or_error_for_default_select_tag(is_subclass): class Foo: pass - class FooConverter(Converter): + ParentClass = Converter if is_subclass else object + + class FooConverter(ParentClass): tags = ["asdf://somewhere.org/tags/foo-*"] types = [Foo] @@ -932,6 +935,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 pytest.warns(AsdfWarning, match="Converter handles multiple tags"): + with ctx_type(exception_class, match="Converter handles multiple tags"): config.add_extension(extension) diff --git a/asdf/extension/_converter.py b/asdf/extension/_converter.py index 857cb02c4..8116ea3d6 100644 --- a/asdf/extension/_converter.py +++ b/asdf/extension/_converter.py @@ -170,7 +170,9 @@ def __init__(self, delegate, extension): raise TypeError(msg) if len(relevant_tags) > 1 and not hasattr(delegate, "select_tag"): - if isinstance(delegate, Converter): + # we cannot use isinstance here because Converter supports + # virtual subclasses + if Converter in delegate.__class__.__bases__: # 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