Skip to content

Commit

Permalink
owdataset: Do not capture self in closure
Browse files Browse the repository at this point in the history
Parameterize and move the functions out of the class.
  • Loading branch information
ales-erjavec committed Jan 19, 2021
1 parent c25f185 commit 73310de
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions Orange/widgets/data/owdatasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ def ensure_local(index_url, file_path, local_cache_path,
return localfiles.localpath_download(*file_path, callback=progress_advance)


def list_remote(server: str) -> Dict[Tuple[str, ...], dict]:
client = ServerFiles(server)
return client.allinfo()


def list_local(path: str) -> Dict[Tuple[str, ...], dict]:
return LocalFiles(path).allinfo()


def format_exception(error):
# type: (BaseException) -> str
return "\n".join(traceback.format_exception_only(type(error), error))
Expand Down Expand Up @@ -256,7 +265,7 @@ def __init__(self):
self.setStatusMessage("Initializing")

self._executor = ThreadPoolExecutor(max_workers=1)
f = self._executor.submit(self.list_remote)
f = self._executor.submit(list_remote, self.INDEX_URL)
w = FutureWatcher(f, parent=self)
w.done.connect(self.__set_index)

Expand Down Expand Up @@ -349,7 +358,7 @@ def __set_index(self, f):
assert f.done()
self.setBlocking(False)
self.setStatusMessage("")
self.allinfo_local = self.list_local()
self.allinfo_local = list_local(self.local_cache_path)

try:
self.allinfo_remote = f.result()
Expand Down Expand Up @@ -385,7 +394,7 @@ def __set_index(self, f):

def __update_cached_state(self):
model = self.view.model().sourceModel()
localinfo = self.list_local()
localinfo = list_local(self.local_cache_path)
assert isinstance(model, QStandardItemModel)
allinfo = []
for i in range(model.rowCount()):
Expand Down Expand Up @@ -552,15 +561,6 @@ def load_and_output(self, path):
def load_data(path):
return Orange.data.Table(path)

def list_remote(self):
# type: () -> Dict[Tuple[str, ...], dict]
client = ServerFiles(server=self.INDEX_URL)
return client.allinfo()

def list_local(self):
# type: () -> Dict[Tuple[str, ...], dict]
return LocalFiles(self.local_cache_path).allinfo()


class FutureWatcher(QObject):
done = Signal(object)
Expand Down

0 comments on commit 73310de

Please sign in to comment.