Skip to content

Commit

Permalink
make AsdfExtension private
Browse files Browse the repository at this point in the history
  • Loading branch information
braingram committed Mar 7, 2023
1 parent 5ea47ca commit 0f1f1d7
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion asdf/_tests/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ def assert_extension_correctness(extension):
Parameters
----------
extension : asdf.AsdfExtension
extension : asdf._AsdfExtension
The extension to validate
"""
__tracebackhide__ = True
Expand Down
4 changes: 2 additions & 2 deletions asdf/_tests/test_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
Validator,
get_cached_extension_manager,
)
from asdf.extension._legacy import AsdfExtension, BuiltinExtension, get_cached_asdf_extension_list
from asdf.extension._legacy import BuiltinExtension, _AsdfExtension, get_cached_asdf_extension_list


def test_builtin_extension():
Expand Down Expand Up @@ -172,7 +172,7 @@ def test_extension_proxy():
proxy = ExtensionProxy(extension)

assert isinstance(proxy, Extension)
assert isinstance(proxy, AsdfExtension)
assert isinstance(proxy, _AsdfExtension)

assert proxy.extension_uri == "asdf://somewhere.org/extensions/minimum-1.0"
assert proxy.legacy_class_names == set()
Expand Down
2 changes: 1 addition & 1 deletion asdf/asdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ def _process_user_extensions(self, extensions):
"""
if extensions is None:
extensions = []
elif isinstance(extensions, (_legacy.AsdfExtension, Extension, ExtensionProxy)):
elif isinstance(extensions, (_legacy._AsdfExtension, Extension, ExtensionProxy)):
extensions = [extensions]
elif isinstance(extensions, _legacy.AsdfExtensionList):
extensions = extensions.extensions
Expand Down
4 changes: 2 additions & 2 deletions asdf/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def add_extension(self, extension):
Parameters
----------
extension : asdf.extension.AsdfExtension or asdf.extension.Extension
extension : asdf.extension.Extension
"""
with self._lock:
extension = ExtensionProxy.maybe_wrap(extension)
Expand All @@ -168,7 +168,7 @@ def remove_extension(self, extension=None, *, package=None):
Parameters
----------
extension : asdf.extension.AsdfExtension or asdf.extension.Extension or str, optional
extension : asdf.extension.Extension or str, optional
An extension instance or URI pattern to remove.
package : str, optional
Remove only extensions provided by this package. If the ``extension``
Expand Down
10 changes: 5 additions & 5 deletions asdf/extension/_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from ._compressor import Compressor
from ._converter import ConverterProxy
from ._legacy import AsdfExtension
from ._legacy import _AsdfExtension
from ._tag import TagDefinition
from ._validator import Validator

Expand Down Expand Up @@ -131,7 +131,7 @@ def validators(self):
return []


class ExtensionProxy(Extension, AsdfExtension):
class ExtensionProxy(Extension, _AsdfExtension):
"""
Proxy that wraps an extension, provides default implementations
of optional methods, and carries additional information on the
Expand All @@ -146,7 +146,7 @@ def maybe_wrap(cls, delegate):
return ExtensionProxy(delegate)

def __init__(self, delegate, package_name=None, package_version=None):
if not isinstance(delegate, (Extension, AsdfExtension)):
if not isinstance(delegate, (Extension, _AsdfExtension)):
msg = "Extension must implement the Extension or AsdfExtension interface"
raise TypeError(msg)

Expand All @@ -156,7 +156,7 @@ def __init__(self, delegate, package_name=None, package_version=None):

self._class_name = get_class_name(delegate)

self._legacy = isinstance(delegate, AsdfExtension)
self._legacy = isinstance(delegate, _AsdfExtension)

# Sort these out up-front so that errors are raised when the extension is loaded
# and not in the middle of the user's session. The extension will fail to load
Expand Down Expand Up @@ -367,7 +367,7 @@ def class_name(self):
@property
def legacy(self):
"""
Get the extension's legacy flag. Subclasses of ``asdf.extension.AsdfExtension``
Get the extension's legacy flag. Subclasses of ``asdf.extension._AsdfExtension``
are marked `True`.
Returns
Expand Down
8 changes: 4 additions & 4 deletions asdf/extension/_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@
from asdf._type_index import AsdfTypeIndex
from asdf.exceptions import AsdfDeprecationWarning

__all__ = ["AsdfExtension"]
__all__ = ["_AsdfExtension"]


class AsdfExtension(metaclass=abc.ABCMeta):
class _AsdfExtension(metaclass=abc.ABCMeta):
"""
Abstract base class defining a (legacy) extension to ASDF.
New code should use `asdf.extension.Extension` instead.
"""

@classmethod
def __subclasshook__(cls, class_):
if cls is AsdfExtension:
if cls is _AsdfExtension:
return hasattr(class_, "types") and hasattr(class_, "tag_mapping")
return NotImplemented

Expand Down Expand Up @@ -173,7 +173,7 @@ def get_cached_asdf_extension_list(extensions):
Parameters
----------
extensions : list of asdf.extension.AsdfExtension
extensions : list of asdf.extension._AsdfExtension
Returns
-------
Expand Down

0 comments on commit 0f1f1d7

Please sign in to comment.