Skip to content

Fix bindlines on Python 3.10+ by using collections.abc.Iterable#520

Open
williamhsiao0403 wants to merge 1 commit into
mementum:masterfrom
williamhsiao0403:fix-bindlines-collections-abc
Open

Fix bindlines on Python 3.10+ by using collections.abc.Iterable#520
williamhsiao0403 wants to merge 1 commit into
mementum:masterfrom
williamhsiao0403:fix-bindlines-collections-abc

Conversation

@williamhsiao0403
Copy link
Copy Markdown

Summary

This fixes LineIterator.bindlines() on modern Python versions where collections.Iterable is no longer available.

bindlines() was still checking iterability via collections.Iterable, which raises AttributeError on Python 3.10+ when an indicator calls bindlines().

The change mirrors the compatibility pattern already used elsewhere in the codebase: use collections.abc when available, and fall back to collections for older Python versions.

Changes

  • Use collections.abc.Iterable in LineIterator.bindlines()
  • Keep backward compatibility with older Python versions
  • Add a regression test for Indicator.bindlines()

Verification

Tested with Python 3.13.1:

python tests/test_lineiterator_bindlines.py
python -c "import test_ind_sma; test_ind_sma.test_run()"
python -c "import test_writer; test_writer.test_run()"
python -m compileall -q backtrader tests/test_lineiterator_bindlines.py

Use collections.abc.Iterable when normalizing bindlines arguments, with a fallback to collections.Iterable for older Python versions.

This prevents AttributeError on Python 3.10+ where collections.Iterable has been removed, and adds a regression test covering Indicator.bindlines().
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant