Skip to content

Conversation

@yfukai
Copy link
Contributor

@yfukai yfukai commented Nov 3, 2025

I encountered a case in which I would like to get the last element of Selection. Since OrderedSet is dict-based, I thought it makes sense to make it reversible so that we can access the last element by next(reversed(s)).

With this motivation, this pull request adds support for reversing iteration in the EventedOrderedSet and OrderedSet classes, and introduces new tests to verify this behavior.

Enhancements to Ordered Set Containers:

  • Added a __reversed__ method to EventedOrderedSet to support reversed iteration, enabling the use of Python's built-in reversed() function on instances of this class.

Testing Improvements:

  • Introduced the test_iterator function in tests/containers/test_evented_set.py to validate both forward and reversed iteration for OrderedSet and EventedOrderedSet, ensuring correct order and compatibility with Python's iterator protocol.

@codspeed-hq
Copy link

codspeed-hq bot commented Nov 3, 2025

CodSpeed Performance Report

Merging #395 will not alter performance

Comparing yfukai:ordered_set_reverse (9723412) with main (250f703)

Summary

✅ 67 untouched

@codecov
Copy link

codecov bot commented Nov 3, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.75%. Comparing base (250f703) to head (9723412).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #395      +/-   ##
==========================================
- Coverage   99.75%   99.75%   -0.01%     
==========================================
  Files          23       23              
  Lines        2459     2456       -3     
==========================================
- Hits         2453     2450       -3     
  Misses          6        6              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tlambert03
Copy link
Member

thanks @yfukai! Nice feature 👍

@tlambert03 tlambert03 merged commit abfd85e into pyapp-kit:main Nov 3, 2025
33 of 34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants