Skip to content

Conversation

@thorwhalen
Copy link
Member

No description provided.

This commit resolves multiple issues with enhanced functionality, better error
handling, and comprehensive test coverage.

## Issues Resolved

### #10: BufferReader.__next__() compatibility
- Modified __next__() to raise StopIteration when stream stopped and no data
- Updated __iter__() to catch StopIteration (prevents RuntimeError in Python 3.7+)
- Now fully compatible with Python's iterator protocol
- Works with builtin next(reader, default) and for loops

### #15: Custom exception classes
- Created stream2py/exceptions.py with exception hierarchy
- Implemented Stream2PyError base class and specific exceptions
- Updated StreamBuffer to use StreamNotStartedError with helpful messages
- Exported exceptions module from main package

### #18: Reader started checks
- Documented that checks already exist in StreamBuffer.mk_reader()
- Enhanced error messages with custom exceptions
- Added comprehensive tests demonstrating correct usage patterns

## Tests Added

- test_buffer_reader_stopiteration.py (4 tests for #10)
  - Test StopIteration raised when stream stopped
  - Test None returned when no data but running
  - Test builtin next() with default values
  - Test for loops terminate correctly

- test_reader_without_context.py (5 tests for #18)
  - Test mk_reader() requires started buffer
  - Test readers work without context manager
  - Test context manager ensures cleanup
  - Test recommended usage patterns

## Documentation

- RESOLVED_ISSUES.md - comprehensive summary of resolved issues
- Updated ISSUE_COMMENTS.md with resolution details for #9, #10, #13, #15, #18
- Clear documentation of when to use context managers

## Test Results

- All 28 tests passing
- +9 new tests in this commit
- 100% passing rate maintained

## Related Issues

- #9: Investigated CI - appears correct, needs clarification
- #13: Applies to external keyboardstream2py package
- #17, #14: Analyzed, documented for future work
@thorwhalen thorwhalen merged commit e338851 into master Nov 15, 2025
0 of 2 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