From 46af9234c20fd21b8de34494c4f86a5ffd8c01a2 Mon Sep 17 00:00:00 2001 From: Priyam Singh Date: Sun, 19 Aug 2018 14:53:47 +0530 Subject: [PATCH] Fixed collections ABCs deprecation warning --- beautifultable/beautifultable.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/beautifultable/beautifultable.py b/beautifultable/beautifultable.py index 030e2eb..b40956c 100644 --- a/beautifultable/beautifultable.py +++ b/beautifultable/beautifultable.py @@ -27,9 +27,15 @@ import itertools import copy import operator -import collections import warnings +try: + # Python 3 + from collections.abc import Iterable +except ImportError: + # Python 2.7 + from collections import Iterable + from .utils import get_output_str, raise_suppressed from .rows import RowData, HeaderData from .meta import AlignmentMetaData, PositiveIntegerMetaData @@ -430,7 +436,7 @@ def _validate_row(self, value, init_table_if_required=True): # TODO: Rename this method # str is also an iterable but it is not a valid row, so # an extra check is required for str - if not isinstance(value, collections.Iterable) or isinstance(value, str): + if not isinstance(value, Iterable) or isinstance(value, str): raise TypeError("parameter must be an iterable") row = list(value) @@ -540,7 +546,7 @@ def __len__(self): def __contains__(self, key): if isinstance(key, str): return key in self._column_headers - elif isinstance(key, collections.Iterable): + elif isinstance(key, Iterable): return key in self._table else: raise TypeError("'key' must be str or Iterable, not {}".format(type(key).__name__))