Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions asdf/generic_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

import numpy as np

from . import util
from ._extern import atomicfile
from .exceptions import DelimiterNotFoundError
from .util import _patched_urllib_parse
Expand Down Expand Up @@ -195,7 +194,7 @@ def read(self, nbytes=None):
return content


class GenericFile(metaclass=util._InheritDocstrings):
class GenericFile:
"""
Base class for an abstraction layer around a number of different
file-like types. Each of its subclasses handles a particular kind
Expand Down Expand Up @@ -321,15 +320,14 @@ def read_blocks(self, size):
yield self.read(thissize)

def write(self, content):
self._fd.write(content)

write.__doc__ = """
Write a string to the file. There is no return value. Due to
buffering, the string may not actually show up in the file
until the flush() or close() method is called.
"""
Write a string to the file. There is no return value. Due to
buffering, the string may not actually show up in the file
until the flush() or close() method is called.

Only available if `writable` returns `True`.
"""
Only available if `writable` returns `True`.
"""
self._fd.write(content)

def write_array(self, array):
"""
Expand Down
42 changes: 0 additions & 42 deletions asdf/util.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import enum
import importlib.util
import inspect
import math
import re
import struct
Expand Down Expand Up @@ -276,47 +275,6 @@ def get_class_name(obj, instance=True):
return f"{typ.__module__}.{typ.__qualname__}"


class _InheritDocstrings(type):
"""
This metaclass makes methods of a class automatically have their
docstrings filled in from the methods they override in the base
class.

If the class uses multiple inheritance, the docstring will be
chosen from the first class in the bases list, in the same way as
methods are normally resolved in Python. If this results in
selecting the wrong docstring, the docstring will need to be
explicitly included on the method.

For example::

>>> from asdf.util import _InheritDocstrings
>>> class A(metaclass=_InheritDocstrings):
... def wiggle(self):
... "Wiggle the thingamajig"
... pass
>>> class B(A):
... def wiggle(self):
... pass
>>> B.wiggle.__doc__
'Wiggle the thingamajig'
"""

def __init__(cls, name, bases, dct):
def is_public_member(key):
return (key.startswith("__") and key.endswith("__") and len(key) > 4) or not key.startswith("_")

for key, val in dct.items():
if inspect.isfunction(val) and is_public_member(key) and val.__doc__ is None:
for base in cls.__mro__[1:]:
super_method = getattr(base, key, None)
if super_method is not None:
val.__doc__ = super_method.__doc__
break

super().__init__(name, bases, dct)


class _NOT_SET_TYPE(enum.Enum):
NOT_SET = "NotSet"

Expand Down
Loading