You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix mypy typing issues and achieve 100% test coverage for pagination
- Add TYPE_CHECKING for proper handling of circular imports
- Fix return type annotations in BaseResource
- Remove unreachable code in BaseResource methods
- Add comprehensive tests for pagination edge cases
- Move imports to top of files following best practices
- Update pagination documentation with implementation details
- Configure test coverage to exclude TYPE_CHECKING blocks
Copy file name to clipboardExpand all lines: docs/PAGINATION.md
+21-1Lines changed: 21 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
Some Fitbit API endpoints return potentially large result sets and support
4
4
pagination. This library provides an easy way to work with these paginated
5
-
endpoints.
5
+
endpoints through a robust and type-safe implementation.
6
6
7
7
## Supported Endpoints
8
8
@@ -87,3 +87,23 @@ Each paginated endpoint has specific constraints:
87
87
88
88
- Max limit: 10 entries per page
89
89
- Only supports `offset=0`
90
+
91
+
## Implementation Details
92
+
93
+
The pagination implementation uses the following approach:
94
+
95
+
### Pagination Iterator
96
+
97
+
- Uses the `PaginatedIterator` class that implements the Python `Iterator` protocol
98
+
- Automatically handles fetching the next page when needed using the `next` URL from pagination metadata
99
+
- Properly handles edge cases like invalid responses, missing pagination data, and API errors
100
+
101
+
### Type Safety
102
+
103
+
- Uses `TYPE_CHECKING` from the typing module to avoid circular imports at runtime
104
+
- Maintains complete type safety and mypy compatibility
105
+
- All pagination-related code has 100% test coverage
106
+
107
+
### Resource Integration
108
+
109
+
Each endpoint that supports pagination has an `as_iterator` parameter that, when set to `True`, returns a `PaginatedIterator` instead of the raw API response. This makes it easy to iterate through all pages of results without manually handling pagination.
0 commit comments