Skip to content

Commit

Permalink
Fix: In last Python versions collections.Iterable -> collections.abc.…
Browse files Browse the repository at this point in the history
…Iterable
  • Loading branch information
WISEPLAT committed Feb 22, 2023
1 parent 77a7ce8 commit 484fc63
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion backtrader/cerebro.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
import itertools
import multiprocessing

try: # For new Python versions
collectionsAbc = collections.abc # collections.Iterable -> collections.abc.Iterable
except AttributeError: # For old Python versions
collectionsAbc = collections # Используем collections.Iterable

import backtrader as bt
from .utils.py3 import (map, range, zip, with_metaclass, string_types,
integer_types)
Expand Down Expand Up @@ -330,7 +335,7 @@ def iterize(iterable):
for elem in iterable:
if isinstance(elem, string_types):
elem = (elem,)
elif not isinstance(elem, collections.Iterable):
elif not isinstance(elem, collectionsAbc.Iterable): # Different functions will be called for different Python versions
elem = (elem,)

niterable.append(elem)
Expand Down
7 changes: 6 additions & 1 deletion backtrader/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
import itertools
import sys

try: # For new Python versions
collectionsAbc = collections.abc # collections.Iterable -> collections.abc.Iterable
except AttributeError: # For old Python versions
collectionsAbc = collections # Используем collections.Iterable

import backtrader as bt
from backtrader.utils.py3 import (map, with_metaclass, string_types,
integer_types)
Expand Down Expand Up @@ -205,7 +210,7 @@ def writedict(self, dct, level=0, recurse=False):
self.writelineseparator(level=level)
self.writeline(kline)
self.writedict(val, level=level + 1, recurse=True)
elif isinstance(val, (list, tuple, collections.Iterable)):
elif isinstance(val, (list, tuple, collectionsAbc.Iterable)): # Для разных версий Python будут вызываться разные функции
line = ', '.join(map(str, val))
self.writeline(kline + ' ' + line)
else:
Expand Down

0 comments on commit 484fc63

Please sign in to comment.