Skip to content

Commit b3e3bec

Browse files
authored
Fix _CountingAttr hack with attrs master (#47)
* use arguments list from attr.attrib to init_CountingAttr * monkey patch _CountingAttr instead
1 parent 3e2b8b0 commit b3e3bec

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
lines changed

xsimlab/variable.py

+12-18
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import itertools
33

44
import attr
5-
from attr._make import _CountingAttr as CountingAttr_
5+
from attr._make import _CountingAttr
66

77

88
class VarType(Enum):
@@ -18,15 +18,19 @@ class VarIntent(Enum):
1818
INOUT = 'inout'
1919

2020

21-
class _CountingAttr(CountingAttr_):
22-
"""A hack to add a custom 'compute' decorator for on-request computation
23-
of on_demand variables.
21+
def compute(self, method):
22+
"""A decorator that, when applied to an on-demand variable, returns a
23+
value for that variable.
24+
2425
"""
26+
self.metadata['compute'] = method
27+
28+
return method
2529

26-
def compute(self, method):
27-
self.metadata['compute'] = method
2830

29-
return method
31+
# monkey patch, waiting for cleaner solution:
32+
# https://github.com/python-attrs/attrs/issues/340
33+
_CountingAttr.compute = compute
3034

3135

3236
def _as_dim_tuple(dims):
@@ -180,17 +184,7 @@ def on_demand(dims=(), group=None, description='', attrs=None):
180184
'attrs': attrs or {},
181185
'description': description}
182186

183-
return _CountingAttr(
184-
default=attr.NOTHING,
185-
validator=None,
186-
repr=False,
187-
cmp=False,
188-
hash=None,
189-
init=False,
190-
converter=None,
191-
metadata=metadata,
192-
type=None,
193-
)
187+
return attr.attrib(metadata=metadata, init=False, cmp=False, repr=False)
194188

195189

196190
def foreign(other_process_cls, var_name, intent='in'):

0 commit comments

Comments
 (0)