Skip to content

Commit

Permalink
Merge pull request #8 from eriknw/repr_must_be_str
Browse files Browse the repository at this point in the history
repr methods must return str.  Also, pass client to remotely.
  • Loading branch information
eriknw authored Jul 23, 2021
2 parents 3821a07 + 5684f1b commit a43d0f5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
12 changes: 8 additions & 4 deletions afar/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ class AfarException(Exception):


class Where:
def __init__(self, where, submit_kwargs=None):
def __init__(self, where, client=None, submit_kwargs=None):
self.where = where
self.client = client
self.submit_kwargs = submit_kwargs

def __enter__(self):
Expand All @@ -37,8 +38,8 @@ def __enter__(self):
def __exit__(self, exc_type, exc_value, exc_traceback): # pragma: no cover
return False

def __call__(self, **submit_kwargs):
return Where(self.where, submit_kwargs)
def __call__(self, *, client=None, **submit_kwargs):
return Where(self.where, client, submit_kwargs)


remotely = Where("remotely")
Expand Down Expand Up @@ -166,9 +167,11 @@ def _exit(self, exc_type, exc_value, exc_traceback):
where = exc_value.args[0]
self._where = where.where
submit_kwargs = where.submit_kwargs or {}
client = where.client
elif issubclass(exc_type, NameError) and exc_value.args[0] in _errors_to_locations:
self._where = _errors_to_locations[exc_value.args[0]]
submit_kwargs = {}
client = None
else:
# The exception is valid
return False
Expand All @@ -189,7 +192,8 @@ def _exit(self, exc_type, exc_value, exc_traceback):
display_expr = self._magic_func._display_expr

if self._where == "remotely":
client = distributed.client._get_global_client()
if client is None:
client = distributed.client._get_global_client()
remote_dict = client.submit(run_afar, self._magic_func, names, futures, **submit_kwargs)
if display_expr:
repr_val = client.submit(
Expand Down
8 changes: 4 additions & 4 deletions afar/reprs.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,7 @@ def get_repr_methods():
return
attr_recorder = AttrRecorder()
ip.display_formatter.format(attr_recorder)
repr_methods = attr_recorder._attrs
repr_methods.append("__repr__")
return repr_methods
return attr_recorder._attrs


def repr_afar(val, repr_methods):
Expand All @@ -118,8 +116,10 @@ def repr_afar(val, repr_methods):
rv = traceback.format_exception(*exc_info)
return rv, method_name, True
else:
if rv is None or not isinstance(rv, str):
continue
return rv, method_name, False
return None, "__repr__", False
return repr(val), "__repr__", False


def display_repr(results):
Expand Down

0 comments on commit a43d0f5

Please sign in to comment.