Commit 5c5cbda2 authored by Theo Steininger's avatar Theo Steininger

Addded NiftyMeta class for doc-string inheritance.

parent 83043583
Pipeline #12188 passed with stage
in 4 minutes and 49 seconds
......@@ -17,13 +17,14 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import abc
from nifty.nifty_meta import NiftyMeta
from keepers import Loggable,\
Versionable
class DomainObject(Versionable, Loggable, object):
__metaclass__ = abc.ABCMeta
__metaclass__ = NiftyMeta
def __init__(self):
# _global_id is used in the Versioning module from keepers
......
......@@ -16,10 +16,14 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from nifty.nifty_meta import NiftyMeta
from keepers import Loggable
class Energy(Loggable, object):
__metaclass__ = NiftyMeta
def __init__(self, position):
self._cache = {}
try:
......
......@@ -17,6 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import abc
from nifty.nifty_meta import NiftyMeta
import numpy as np
......@@ -26,7 +27,7 @@ from .line_searching import LineSearchStrongWolfe
class QuasiNewtonMinimizer(Loggable, object):
__metaclass__ = abc.ABCMeta
__metaclass__ = NiftyMeta
def __init__(self, line_searcher=LineSearchStrongWolfe(), callback=None,
convergence_tolerance=1E-4, convergence_level=3,
......
# -*- coding: utf-8 -*-
import abc
class DocStringInheritor(type):
"""
A variation on
http://groups.google.com/group/comp.lang.python/msg/26f7b4fcb4d66c95
by Paul McGuire
"""
def __new__(meta, name, bases, clsdict):
if not('__doc__' in clsdict and clsdict['__doc__']):
for mro_cls in (mro_cls for base in bases
for mro_cls in base.mro()):
doc = mro_cls.__doc__
if doc:
clsdict['__doc__'] = doc
break
for attr, attribute in clsdict.items():
if not attribute.__doc__:
for mro_cls in (mro_cls for base in bases
for mro_cls in base.mro()
if hasattr(mro_cls, attr)):
doc = getattr(getattr(mro_cls, attr), '__doc__')
if doc:
if isinstance(attribute, property):
clsdict[attr] = property(attribute.fget,
attribute.fset,
attribute.fdel,
doc)
else:
attribute.__doc__ = doc
break
return super(DocStringInheritor, meta).__new__(meta, name,
bases, clsdict)
class NiftyMeta(DocStringInheritor, abc.ABCMeta):
pass
......@@ -17,6 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import abc
from nifty.nifty_meta import NiftyMeta
from keepers import Loggable
from nifty.field import Field
......@@ -24,7 +25,7 @@ import nifty.nifty_utilities as utilities
class LinearOperator(Loggable, object):
__metaclass__ = abc.ABCMeta
__metaclass__ = NiftyMeta
def __init__(self):
pass
......
from abc import ABCMeta, abstractmethod
from nifty.nifty_meta import NiftyMeta
class PlotlyWrapper(object):
__metaclass__ = ABCMeta
__metaclass__ = NiftyMeta
@abstractmethod
def to_plotly(self):
......
......@@ -16,8 +16,6 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import abc
import numpy as np
from nifty.field import Field
......@@ -38,8 +36,6 @@ class Prober(object):
"""
__metaclass__ = abc.ABCMeta
def __init__(self, domain=None, distribution_strategy=None, probe_count=8,
random_type='pm1', compute_variance=False):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment