Skip to content

Issue/676 improve developer experience #677

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
- Deundre Williams [@deundrewilliams](https://github.com/deundrewilliams)
- Devin Singh [@devints47](https://github.com/devints47)
- Dmitry Savransky [@dsavransky](https://github.com/dsavransky)
- Elias [@HandcartCactus](https://github.com/HandcartCactus)
- Elise Heron [@thedarkestknight](https://github.com/thedarkestknight)
- Elli Howard [@qwertynerd97](https://github.com/qwertynerd97)
- Erik Tews [@eriktews](https://github.com/eriktews)
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
### Backstage

- Updated deploy Action to use more modern processes.
- Updated `PaginatedList` to be type-aware, showing which class is included in the response. (Thanks [@HandcartCactus](https://github.com/HandcartCactus))

## [3.3.0] - 2023-08-27

Expand Down
13 changes: 9 additions & 4 deletions canvasapi/paginated_list.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
from __future__ import annotations

import re
from typing import Iterable, Iterator, Type, TypeVar

T = TypeVar("T")


class PaginatedList(object):
class PaginatedList(Iterable[T]):
"""
Abstracts `pagination of Canvas API \
<https://canvas.instructure.com/doc/api/file.pagination.html>`_.
Expand All @@ -19,14 +24,14 @@ def __getitem__(self, index):

def __init__(
self,
content_class,
content_class: Type[T],
requester,
request_method,
first_url,
extra_attribs=None,
_root=None,
_url_override=None,
**kwargs
**kwargs,
):
"""
:param content_class: The expected type to return in the list.
Expand Down Expand Up @@ -60,7 +65,7 @@ def __init__(
self._root = _root
self._url_override = _url_override

def __iter__(self):
def __iter__(self) -> Iterator[T]:
for element in self._elements:
yield element
while self._has_next():
Expand Down
Loading