Skip to content

Commit a43d0f5

Browse files
authored
Merge pull request #8 from eriknw/repr_must_be_str
repr methods must return str. Also, pass client to remotely.
2 parents 3821a07 + 5684f1b commit a43d0f5

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

afar/core.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ class AfarException(Exception):
2727

2828

2929
class Where:
30-
def __init__(self, where, submit_kwargs=None):
30+
def __init__(self, where, client=None, submit_kwargs=None):
3131
self.where = where
32+
self.client = client
3233
self.submit_kwargs = submit_kwargs
3334

3435
def __enter__(self):
@@ -37,8 +38,8 @@ def __enter__(self):
3738
def __exit__(self, exc_type, exc_value, exc_traceback): # pragma: no cover
3839
return False
3940

40-
def __call__(self, **submit_kwargs):
41-
return Where(self.where, submit_kwargs)
41+
def __call__(self, *, client=None, **submit_kwargs):
42+
return Where(self.where, client, submit_kwargs)
4243

4344

4445
remotely = Where("remotely")
@@ -166,9 +167,11 @@ def _exit(self, exc_type, exc_value, exc_traceback):
166167
where = exc_value.args[0]
167168
self._where = where.where
168169
submit_kwargs = where.submit_kwargs or {}
170+
client = where.client
169171
elif issubclass(exc_type, NameError) and exc_value.args[0] in _errors_to_locations:
170172
self._where = _errors_to_locations[exc_value.args[0]]
171173
submit_kwargs = {}
174+
client = None
172175
else:
173176
# The exception is valid
174177
return False
@@ -189,7 +192,8 @@ def _exit(self, exc_type, exc_value, exc_traceback):
189192
display_expr = self._magic_func._display_expr
190193

191194
if self._where == "remotely":
192-
client = distributed.client._get_global_client()
195+
if client is None:
196+
client = distributed.client._get_global_client()
193197
remote_dict = client.submit(run_afar, self._magic_func, names, futures, **submit_kwargs)
194198
if display_expr:
195199
repr_val = client.submit(

afar/reprs.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,7 @@ def get_repr_methods():
9393
return
9494
attr_recorder = AttrRecorder()
9595
ip.display_formatter.format(attr_recorder)
96-
repr_methods = attr_recorder._attrs
97-
repr_methods.append("__repr__")
98-
return repr_methods
96+
return attr_recorder._attrs
9997

10098

10199
def repr_afar(val, repr_methods):
@@ -118,8 +116,10 @@ def repr_afar(val, repr_methods):
118116
rv = traceback.format_exception(*exc_info)
119117
return rv, method_name, True
120118
else:
119+
if rv is None or not isinstance(rv, str):
120+
continue
121121
return rv, method_name, False
122-
return None, "__repr__", False
122+
return repr(val), "__repr__", False
123123

124124

125125
def display_repr(results):

0 commit comments

Comments
 (0)