Skip to content

Commit

Permalink
MAINT: pylint improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
adler-j committed Nov 26, 2015
1 parent 65fc8bd commit 69b729b
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 22 deletions.
2 changes: 2 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,15 @@ load-plugins=
# --disable=W"

# Disable all messages caused solely by 'future' imports and functions
# and also backslash to enable :math: and not callable since it fails with inherited __call__.
disable=redefined-builtin,
super-on-old-class,
missing-super-argument,
no-value-for-parameter,
no-member,
too-many-function-args,
anomalous-backslash-in-string,
not-callable,

# redefined-builtin: 'object', 'range', 'str', 'super' are redefined, that's okay
# super-on-old-class: classes are erroneously interpreted as old-style
Expand Down
2 changes: 1 addition & 1 deletion odl/discr/lp_discr.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ def uniform_discr(fspace, nsamples, exponent=2.0, interp='nearest',
weight = np.prod(grid.stride)
else: # weighting_ == 'consistent'
# TODO: implement
raise NotImplemented
raise NotImplementedError

if dtype is not None:
dspace = ds_type(grid.ntotal, dtype=dtype, weight=weight,
Expand Down
4 changes: 2 additions & 2 deletions odl/operator/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1475,8 +1475,8 @@ def simple_operator(call=None, apply=None, inv=None, deriv=None,
if apply is not None:
attrs['_apply'] = _bound_method(apply)

simple_operator = _OperatorMeta('SimpleOperator', (Operator,), attrs)
return simple_operator(dom, ran, linear)
simple_op_cls = _OperatorMeta('SimpleOperator', (Operator,), attrs)
return simple_op_cls(dom, ran, linear)


if __name__ == '__main__':
Expand Down
4 changes: 2 additions & 2 deletions odl/operator/pspace_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def __init__(self, operators, dom=None, ran=None):
if sub_domain is None:
raise ValueError('Col {} empty, unable to determine '
'domain, please use `dom` parameter'
''.format(col, sub_domain))
''.format(col))

dom = ProductSpace(*domains)

Expand All @@ -194,7 +194,7 @@ def __init__(self, operators, dom=None, ran=None):
if sub_range is None:
raise ValueError('Row {} empty, unable to determine '
'range, please use `ran` parameter'
''.format(row, sub_range))
''.format(row))

ran = ProductSpace(*ranges)

Expand Down
2 changes: 1 addition & 1 deletion odl/set/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ def dist(self, point, ord=2.0):
if len(point) != self.ndim:
raise ValueError('length {} of point {} does not match '
'the dimension {} of the set {}.'
''.format(len(point), point, self.ndim))
''.format(len(point), point, self.ndim, self))

i_larger = np.where(point > self._end)
i_smaller = np.where(point < self._begin)
Expand Down
4 changes: 2 additions & 2 deletions odl/set/sets.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ def __contains__(self, other):
def contains_set(self, other):
"""Test if ``other`` is a subset of this set.
Implementing this method is optional.
Implementing this method is optional. Default it tests for equality.
"""
raise NotImplementedError("'contains_set' method not implemented.")
return self == other

@abstractmethod
def __eq__(self, other):
Expand Down
4 changes: 3 additions & 1 deletion odl/set/space.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class LinearSpace(Set):
"""

@abstractmethod
def element(self, inp=None):
def element(self, inp=None, **kwargs):
"""Create a `LinearSpaceVector` from ``inp`` or from scratch.
If called without ``inp`` argument, an arbitrary element in the
Expand All @@ -67,6 +67,8 @@ def element(self, inp=None):
----------
inp : `object`, optional
The input data from which to create the element
**args : `dict`, optional
Optional further arguments.
Returns
-------
Expand Down
8 changes: 6 additions & 2 deletions odl/space/base_ntuples.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def copy(self):
"""Create an identical (deep) copy of this vector."""

@abstractmethod
def asarray(self, start=None, stop=None, step=None):
def asarray(self, start=None, stop=None, step=None, out=None):
"""Extract the data of this array as a numpy array.
Parameters
Expand All @@ -220,6 +220,8 @@ def asarray(self, start=None, stop=None, step=None):
`None` means the last element.
start : `int`, optional
Step length. `None` means 1.
out : `numpy.ndarray`
Array to write result to.
Returns
-------
Expand Down Expand Up @@ -476,14 +478,16 @@ def __eq__(self, other):
def equiv(self, other):
"""Test if ``other`` is an equivalent inner product.
Should be overwritten, default tests for equality.
Returns
-------
equivalent : `bool`
`True` if ``other`` is a `FnWeightingBase` instance which
yields the same result as this inner product for any
input, `False` otherwise.
"""
raise NotImplementedError
return self == other

def inner(self, x1, x2):
"""Calculate the inner product of two vectors.
Expand Down
19 changes: 8 additions & 11 deletions odl/space/cu_ntuples.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,8 +573,8 @@ def __init__(self, size, dtype, **kwargs):
exponent = kwargs.pop('exponent', 2.0)

# Check validity of option combination (3 or 4 out of 4 must be None)
from builtins import sum
if sum(x is None for x in (dist, norm, inner, weight)) < 3:
from builtins import sum as py_sum
if py_sum(x is None for x in (dist, norm, inner, weight)) < 3:
raise ValueError('invalid combination of options `weight`, '
'`dist`, `norm` and `inner`.')
if weight is not None:
Expand Down Expand Up @@ -1564,10 +1564,9 @@ def __init__(self, inner, dist_using_inner=True):
''.format(inner))
self._inner_impl = inner

@property
def inner(self):
def inner(self, x1, x2):
"""Custom inner product of this instance.."""
return self._inner_impl
return self._inner_impl(x1, x2)

def __eq__(self, other):
"""``inner.__eq__(other) <==> inner == other``.
Expand Down Expand Up @@ -1630,10 +1629,9 @@ def inner(self, x1, x2):
"""Inner product is not defined for custom distance."""
raise NotImplementedError

@property
def norm(self):
def norm(self, x):
"""Custom norm of this instance.."""
return self._norm_impl
return self._norm_impl(x)

def __eq__(self, other):
"""``inner.__eq__(other) <==> inner == other``.
Expand Down Expand Up @@ -1687,10 +1685,9 @@ def __init__(self, dist):
''.format(dist))
self._dist_impl = dist

@property
def dist(self):
def dist(self, x1, x2):
"""Custom distance of this instance.."""
return self._dist_impl
return self._dist_impl(x1, x2)

def inner(self, x1, x2):
"""Inner product is not defined for custom distance."""
Expand Down

0 comments on commit 69b729b

Please sign in to comment.