Skip to content

Unittest islice_extended impact on iterated elements lifecycle#996

Merged
bbayles merged 3 commits intomore-itertools:masterfrom
ben42code:u/ben42code/islice_extended_unittest
Jun 2, 2025
Merged

Unittest islice_extended impact on iterated elements lifecycle#996
bbayles merged 3 commits intomore-itertools:masterfrom
ben42code:u/ben42code/islice_extended_unittest

Conversation

@ben42code
Copy link
Copy Markdown
Contributor

@ben42code ben42code commented May 31, 2025

Unittest the current behavior/impact of islice_extended on the iterated elements lifecycle.

  • Does not introduce any production change.✅
  • Disclaimer: several potential lifecycle improvements are being highlighted in the unit test. Even though most/all of them could be addressed with low impact changes (similar to Improve islice_extended memory usage when start<0 and step>0 #995), they should be handled (or not) in dedicated pull requests/discussions. Not in scope for this pull request.

Issue reference

This is a follow up for:

Changes

Added unit test tests.test_more.IsliceExtendedTests.test_elements_lifecycle

Checks and tests

test_all (tests.test_more.IsliceExtendedTests.test_all) ... ok
test_elements_lifecycle (tests.test_more.IsliceExtendedTests.test_elements_lifecycle) ... ok
test_invalid_slice (tests.test_more.IsliceExtendedTests.test_invalid_slice) ... ok
test_slicing (tests.test_more.IsliceExtendedTests.test_slicing) ... ok
test_slicing_extensive (tests.test_more.IsliceExtendedTests.test_slicing_extensive) ... ok
test_zero_step (tests.test_more.IsliceExtendedTests.test_zero_step) ... ok

unit test the current behavior of islice_extended on the iterated elements lifecycle.
this is a follow up for the fix of issue more-itertools#994
@ben42code
Copy link
Copy Markdown
Contributor Author

ben42code commented May 31, 2025

Coverage failed on pypy 3.10. Looking at it.

ben42code added 2 commits May 31, 2025 21:53
- Pypy does not count references. It fully relies on garbage collection
- force a garbage collection on non-CPython interpreter.
@ben42code
Copy link
Copy Markdown
Contributor Author

Pypy fully relies on garbage collection. CPython does reference counting (on top of garbage collection).
Updated unit test to force a garbage collection on non-CPython interpreter.
...and fixed some formatting issues 😁

@JamesParrott
Copy link
Copy Markdown
Contributor

I've taken a quick look at the code for IteratorWithWeakReferences, TestCase, and the loop in test_elements_lifecycle that runs them all. It all seems good. Well done Ben getting it to run on PyPy too.

@bbayles bbayles merged commit 5ae2f2b into more-itertools:master Jun 2, 2025
6 checks passed
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.

3 participants