Skip to content

Commit dd7a797

Browse files
authored
Merge pull request #24 from nyurik/fix-python310
Support python 3.10 collections
2 parents 2c740b8 + 6e09de4 commit dd7a797

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

ascii_graph/__init__.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@
44
from __future__ import unicode_literals
55
import sys
66
import re
7-
import collections
87
import copy
98

9+
if sys.version < '3' or sys.version.startswith('3.0.') or sys.version.startswith('3.1.') or sys.version.startswith('3.2.'):
10+
from collections import Iterable
11+
else:
12+
from collections.abc import Iterable
13+
1014

1115
class Pyasciigraph:
1216

@@ -143,7 +147,7 @@ def _get_thresholds(self, data):
143147
totalvalue_len = 0
144148

145149
# If we have a list of values for the item
146-
if isinstance(value, collections.Iterable):
150+
if isinstance(value, Iterable):
147151
icount = 0
148152
maxvalue = 0
149153
minvalue = 0
@@ -217,7 +221,7 @@ def _gen_graph_string_part(
217221
neg_width = int(abs(float(min_neg_value)) * float(graph_length) / float(all_width))
218222
pos_width = int(abs(max_value) * graph_length / all_width)
219223

220-
if isinstance(value, collections.Iterable):
224+
if isinstance(value, Iterable):
221225
accuvalue = 0
222226
totalstring = ""
223227
totalsquares = 0
@@ -283,7 +287,7 @@ def _gen_value_string(self, value, min_neg_value, color, start_value_pos, start_
283287
"""Generate the value string + padding
284288
"""
285289
icount = 0
286-
if isinstance(value, collections.Iterable) and self.multivalue:
290+
if isinstance(value, Iterable) and self.multivalue:
287291
for (ivalue, icolor) in value:
288292
if icount == 0:
289293
# total_len is needed because the color characters count
@@ -299,7 +303,7 @@ def _gen_value_string(self, value, min_neg_value, color, start_value_pos, start_
299303
self._trans_hr(ivalue),
300304
icolor)
301305
icount += 1
302-
elif isinstance(value, collections.Iterable):
306+
elif isinstance(value, Iterable):
303307
max_value = min_neg_value
304308
color = None
305309
for (ivalue, icolor) in value:
@@ -353,7 +357,7 @@ def _sanitize_string(self, string):
353357
def _sanitize_value(self, value):
354358
"""try to values to UTF-8
355359
"""
356-
if isinstance(value, collections.Iterable):
360+
if isinstance(value, Iterable):
357361
newcollection = []
358362
for i in value:
359363
if len(i) == 1:
@@ -368,7 +372,7 @@ def _sanitize_data(self, data):
368372
ret = []
369373
for item in data:
370374
if (len(item) == 2):
371-
if isinstance(item[1], collections.Iterable):
375+
if isinstance(item[1], Iterable):
372376
ret.append(
373377
(self._sanitize_string(item[0]),
374378
self._sanitize_value(item[1]),

0 commit comments

Comments
 (0)