diff --git a/backtrader/lineiterator.py b/backtrader/lineiterator.py index 2ead478b8..30ecea96f 100644 --- a/backtrader/lineiterator.py +++ b/backtrader/lineiterator.py @@ -25,6 +25,11 @@ import operator import sys +try: + collectionsAbc = collections.abc +except AttributeError: + collectionsAbc = collections + from .utils.py3 import map, range, zip, with_metaclass, string_types from .utils import DotDict @@ -226,7 +231,7 @@ def bindlines(self, owner=None, own=None): if isinstance(owner, string_types): owner = [owner] - elif not isinstance(owner, collections.Iterable): + elif not isinstance(owner, collectionsAbc.Iterable): owner = [owner] if not own: @@ -234,7 +239,7 @@ def bindlines(self, owner=None, own=None): if isinstance(own, string_types): own = [own] - elif not isinstance(own, collections.Iterable): + elif not isinstance(own, collectionsAbc.Iterable): own = [own] for lineowner, lineown in zip(owner, own): diff --git a/tests/test_lineiterator_bindlines.py b/tests/test_lineiterator_bindlines.py new file mode 100644 index 000000000..47c997cda --- /dev/null +++ b/tests/test_lineiterator_bindlines.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python +# -*- coding: utf-8; py-indent-offset:4 -*- +############################################################################### +# +# Copyright (C) 2015-2023 Daniel Rodriguez +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +############################################################################### +from __future__ import (absolute_import, division, print_function, + unicode_literals) + +import datetime + +import testcommon + +import backtrader as bt + + +class BindLinesStrategy(bt.Strategy): + params = dict(main=False) + + def __init__(self): + self.sma = bt.ind.SMA(self.data, period=5) + self.sma.bindlines() + + +def test_bindlines_python_310_collections_abc(main=False): + data = testcommon.getdata(0, + fromdate=datetime.datetime(2006, 1, 1), + todate=datetime.datetime(2006, 1, 31)) + + testcommon.runtest([data], + BindLinesStrategy, + runonce=False, + preload=False, + exbar=False, + main=main) + + +if __name__ == '__main__': + test_bindlines_python_310_collections_abc(main=True)