Skip to content

Commit

Permalink
New style classes everywhere (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
benbovy committed Sep 24, 2019
1 parent b01c792 commit 2715c49
Show file tree
Hide file tree
Showing 17 changed files with 41 additions and 41 deletions.
2 changes: 1 addition & 1 deletion doc/examples/landscape-evolution-model.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2083,7 +2083,7 @@
"\n",
"\n",
"@xs.process\n",
"class VariableUplift(object):\n",
"class VariableUplift:\n",
" \"\"\"Compute spatially variable uplift as a linear function of x.\"\"\"\n",
" \n",
" x_coef = xs.variable(description='uplift function x coefficient')\n",
Expand Down
16 changes: 8 additions & 8 deletions doc/scripts/advection_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


@xs.process
class AdvectionLax1D(object):
class AdvectionLax1D:
"""Wrap 1-dimensional advection in a single Process."""

spacing = xs.variable(description='grid spacing')
Expand Down Expand Up @@ -36,7 +36,7 @@ def finalize_step(self):


@xs.process
class UniformGrid1D(object):
class UniformGrid1D:
"""Create a 1-dimensional, equally spaced grid."""

spacing = xs.variable(description='uniform spacing')
Expand All @@ -48,7 +48,7 @@ def initialize(self):


@xs.process
class ProfileU(object):
class ProfileU:
"""Compute the evolution of the profile of quantity `u`."""

u_vars = xs.group('u_vars')
Expand All @@ -63,7 +63,7 @@ def finalize_step(self):


@xs.process
class AdvectionLax(object):
class AdvectionLax:
"""Advection using finite difference (Lax method) on
a fixed grid with periodic boundary conditions.
Expand All @@ -84,7 +84,7 @@ def run_step(self, dt):


@xs.process
class InitUGauss(object):
class InitUGauss:
"""Initialize `u` profile using a Gaussian pulse."""

loc = xs.variable(description='location of initial pulse')
Expand All @@ -103,7 +103,7 @@ def initialize(self):


@xs.process
class SourcePoint(object):
class SourcePoint:
"""Source point for quantity `u`.
The location of the source point is adjusted to coincide with
Expand Down Expand Up @@ -131,7 +131,7 @@ def run_step(self, dt):


@xs.process
class InitUFlat(object):
class InitUFlat:
"""Flat initial profile of `u`."""

x = xs.foreign(UniformGrid1D, 'x')
Expand All @@ -149,7 +149,7 @@ def initialize(self):


@xs.process
class FixedGridParams(object):
class FixedGridParams:
spacing = xs.foreign(UniformGrid1D, 'spacing', intent='out')
length = xs.foreign(UniformGrid1D, 'length', intent='out')

Expand Down
2 changes: 1 addition & 1 deletion xsimlab/dot.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def _get_target_keys(p_obj, var_name):
)


class _GraphBuilder(object):
class _GraphBuilder:

def __init__(self, model, graph_attr):
self.model = model
Expand Down
2 changes: 1 addition & 1 deletion xsimlab/drivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from .utils import variables_dict


class BaseSimulationDriver(object):
class BaseSimulationDriver:
"""Base class that provides a minimal interface for creating
simulation drivers (should be inherited).
Expand Down
2 changes: 1 addition & 1 deletion xsimlab/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def _flatten_keys(key_seq):
return flat_keys


class _ModelBuilder(object):
class _ModelBuilder:
"""Used to iteratively build a new model.
This builder implements the following tasks:
Expand Down
2 changes: 1 addition & 1 deletion xsimlab/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def getter_store_or_on_demand(self):
return property(fget=getter_store_or_on_demand, doc=var_details(var))


class _ProcessBuilder(object):
class _ProcessBuilder:
"""Used to iteratively create a new process class.
The original class must be already "attr-yfied", i.e., it must
Expand Down
2 changes: 1 addition & 1 deletion xsimlab/stores.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import numpy as np


class InMemoryOutputStore(object):
class InMemoryOutputStore:
"""A simple, in-memory store for model outputs.
It basically consists of a Python dictionary with lists as values,
Expand Down
10 changes: 5 additions & 5 deletions xsimlab/tests/fixture_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


@xs.process
class Profile(object):
class Profile:
u = xs.variable(dims='x', description='quantity u', intent='inout')
u_diffs = xs.group('diff')
u_opp = xs.on_demand(dims='x')
Expand All @@ -33,7 +33,7 @@ def _get_u_opposite(self):


@xs.process
class InitProfile(object):
class InitProfile:
n_points = xs.variable(description='nb. of profile points')
u = xs.foreign(Profile, 'u', intent='out')

Expand All @@ -43,7 +43,7 @@ def initialize(self):


@xs.process
class Roll(object):
class Roll:
shift = xs.variable(description=('shift profile by a nb. of points'),
attrs={'units': 'unitless'})
u = xs.foreign(Profile, 'u')
Expand All @@ -54,7 +54,7 @@ def run_step(self, *args):


@xs.process
class Add(object):
class Add:
offset = xs.variable(description=('offset * dt added every time step '
'to profile u'))
u_diff = xs.variable(group='diff', intent='out')
Expand All @@ -64,7 +64,7 @@ def run_step(self, dt):


@xs.process
class AddOnDemand(object):
class AddOnDemand:
offset = xs.variable(description='offset added to profile u')
u_diff = xs.on_demand(group='diff')

Expand Down
8 changes: 4 additions & 4 deletions xsimlab/tests/fixture_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


@xs.process
class SomeProcess(object):
class SomeProcess:
"""Just used for foreign variables in ExampleProcess."""
some_var = xs.variable(group='some_group', intent='out')
some_od_var = xs.on_demand(group='some_group')
Expand All @@ -18,14 +18,14 @@ def compute_some_od_var(self):


@xs.process
class AnotherProcess(object):
class AnotherProcess:
"""Just used for foreign variables in ExampleProcess."""
another_var = xs.variable()
some_var = xs.foreign(SomeProcess, 'some_var')


@xs.process
class ExampleProcess(object):
class ExampleProcess:
"""A process with complete interface for testing."""
in_var = xs.variable(dims=['x', ('x', 'y')], description='input variable')
out_var = xs.variable(group='example_group', intent='out')
Expand Down Expand Up @@ -96,7 +96,7 @@ def _init_process(p_cls, p_name, model, store, store_keys=None, od_keys=None):

@pytest.fixture
def processes_with_store():
class FakeModel(object):
class FakeModel:
def __init__(self):
self._processes = {}

Expand Down
4 changes: 2 additions & 2 deletions xsimlab/tests/test_drivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def xarray_driver(in_dataset, model):
return XarraySimulationDriver(in_dataset, model, store, out_store)


class TestBaseDriver(object):
class TestBaseDriver:

def test_bind_store(self, base_driver):
base_driver.store[('init_profile', 'n_points')] = 10
Expand Down Expand Up @@ -63,7 +63,7 @@ def test_get_dims_from_variable(array, clock, expected):
assert _get_dims_from_variable(array, var, clock) == expected


class TestXarraySimulationDriver(object):
class TestXarraySimulationDriver:

def test_constructor(self, in_dataset, model):
store = {}
Expand Down
2 changes: 1 addition & 1 deletion xsimlab/tests/test_formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def test_process_repr(example_process_obj, processes_with_store,
assert repr_process(process_in_model) == example_process_in_model_repr

@xs.process
class Dummy(object):
class Dummy:
def initialize(self):
pass

Expand Down
10 changes: 5 additions & 5 deletions xsimlab/tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from xsimlab.tests.fixture_model import AddOnDemand, InitProfile, Profile


class TestModelBuilder(object):
class TestModelBuilder:

def test_bind_processes(self, model):
assert model._processes['profile'].__xsimlab_model__ is model
Expand Down Expand Up @@ -54,7 +54,7 @@ def test_get_all_variables(self, model):

def test_ensure_no_intent_conflict(self, model):
@xs.process
class Foo(object):
class Foo:
u = xs.foreign(Profile, 'u', intent='out')

with pytest.raises(ValueError) as excinfo:
Expand Down Expand Up @@ -92,12 +92,12 @@ def test_sort_processes(self, model, p_name, dep_p_name):

def test_sort_processes_cycle(self, model):
@xs.process
class Foo(object):
class Foo:
in_var = xs.variable()
out_var = xs.variable(intent='out')

@xs.process
class Bar(object):
class Bar:
in_foreign = xs.foreign(Foo, 'out_var')
out_foreign = xs.foreign(Foo, 'in_var', intent='out')

Expand Down Expand Up @@ -126,7 +126,7 @@ class InheritedProfile(Profile):
assert "multiple processes" in str(excinfo.value)


class TestModel(object):
class TestModel:

def test_constructor(self):
with pytest.raises(TypeError) as excinfo:
Expand Down
10 changes: 5 additions & 5 deletions xsimlab/tests/test_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


def test_ensure_process_decorated():
class NotAProcess(object):
class NotAProcess:
pass

with pytest.raises(NotAProcessClassError) as excinfo:
Expand Down Expand Up @@ -88,21 +88,21 @@ def test_process_properties_readonly(p_cls, var_name, prop_is_read_only):
def test_process_properties_errors():
with pytest.raises(ValueError) as excinfo:
@xs.process
class Process1(object):
class Process1:
invalid_var = xs.foreign(ExampleProcess, 'group_var')

assert "links to group variable" in str(excinfo.value)

with pytest.raises(ValueError) as excinfo:
@xs.process
class Process2(object):
class Process2:
invalid_var = xs.foreign(ExampleProcess, 'out_var', intent='out')

assert "both have intent='out'" in str(excinfo.value)

with pytest.raises(KeyError) as excinfo:
@xs.process
class Process3(object):
class Process3:
var = xs.on_demand()

assert "No compute method found" in str(excinfo.value)
Expand Down Expand Up @@ -138,7 +138,7 @@ def test_process_properties_values(processes_with_store):
def test_process_decorator():
with pytest.raises(NotImplementedError):
@xs.process(autodoc=True)
class Dummy(object):
class Dummy:
pass


Expand Down
2 changes: 1 addition & 1 deletion xsimlab/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_import_required():
assert err_msg in str(excinfo.value)


class TestAttrMapping(object):
class TestAttrMapping:

@pytest.fixture
def attr_mapping(self):
Expand Down
2 changes: 1 addition & 1 deletion xsimlab/tests/test_xr_accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def test_flatten_outputs_error():
assert "Cannot interpret" in str(excinfo.value)


class TestSimlabAccessor(object):
class TestSimlabAccessor:

_clock_key = xr_accessor.SimlabAccessor._clock_key
_master_clock_key = xr_accessor.SimlabAccessor._master_clock_key
Expand Down
4 changes: 2 additions & 2 deletions xsimlab/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def import_required(mod_name, error_msg):
raise RuntimeError(error_msg)


class AttrMapping(object):
class AttrMapping:
"""A class similar to `collections.abc.Mapping`,
which also allows getting keys with attribute access.
Expand Down Expand Up @@ -135,7 +135,7 @@ def __dir__(self):
return sorted(set(dir(type(self)) + extra_attrs))


class ContextMixin(object):
class ContextMixin:
"""Functionality for objects that put themselves in a context using
the `with` statement.
Expand Down
2 changes: 1 addition & 1 deletion xsimlab/xr_accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def _flatten_outputs(output_vars):


@register_dataset_accessor('xsimlab')
class SimlabAccessor(object):
class SimlabAccessor:
"""Simlab extension to :class:`xarray.Dataset`."""

_clock_key = '__xsimlab_output_clock__'
Expand Down

0 comments on commit 2715c49

Please sign in to comment.