Skip to content

Commit

Permalink
Import ABC from collections.abc instead of collections for Python 3.9…
Browse files Browse the repository at this point in the history
… compatibility.
  • Loading branch information
tirkarthi committed Mar 3, 2020
1 parent 146da43 commit a97850e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
8 changes: 6 additions & 2 deletions trains/backend_interface/metrics/reporter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import collections
import json

try:
from collections.abc import Iterable
except ImportError:
from collections import Iterable

import six
import numpy as np
from threading import Thread, Event
Expand Down Expand Up @@ -152,7 +156,7 @@ def report_vector(self, title, series, values, iter):
:param iter: Iteration number
:type value: int
"""
if not isinstance(values, collections.Iterable):
if not isinstance(values, Iterable):
raise ValueError('values: expected an iterable')
ev = VectorEvent(metric=self._normalize_name(title), variant=self._normalize_name(series), values=values, iter=iter)
self._report(ev)
Expand Down
8 changes: 6 additions & 2 deletions trains/backend_interface/task/task.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
""" Backend task management support """
import collections
import itertools
import logging
import os
from enum import Enum
from threading import Thread
from multiprocessing import RLock

try:
from collections.abc import Iterable
except ImportError:
from collections import Iterable

import six
from six.moves.urllib.parse import quote

Expand Down Expand Up @@ -587,7 +591,7 @@ def set_parameters(self, *args, **kwargs):
a single key/value dictionary.
:param kwargs: Key/value pairs, merged into the parameters dictionary created from `args`.
"""
if not all(isinstance(x, (dict, collections.Iterable)) for x in args):
if not all(isinstance(x, (dict, Iterable)) for x in args):
raise ValueError('only dict or iterable are supported as positional arguments')

update = kwargs.pop('__update', False)
Expand Down
5 changes: 2 additions & 3 deletions trains/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
import threading
import time
from argparse import ArgumentParser
from collections import Callable
from tempfile import mkstemp

try:
from collections.abc import Sequence
from collections.abc import Callable, Sequence
except ImportError:
from collections import Sequence
from collections import Callable, Sequence

from typing import Optional

Expand Down

0 comments on commit a97850e

Please sign in to comment.