Skip to content

Commit f94370a

Browse files
committed
feat: allow returning “Iterable” along lists
Based on the discussion we had during the arch about ogr pagination, let's start with relaxing the abstract interface to allow returning iterables instead of full lists. Signed-off-by: Matej Focko <[email protected]>
1 parent 1509537 commit f94370a

File tree

3 files changed

+40
-25
lines changed

3 files changed

+40
-25
lines changed

ogr/abstract.py

+38-23
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ def edited(self) -> datetime.datetime:
245245
"""Datetime of last edit of the comment."""
246246
return self._edited
247247

248-
def get_reactions(self) -> list[Reaction]:
248+
def get_reactions(self) -> Union[list[Reaction], Iterable[Reaction]]:
249249
"""Returns list of reactions."""
250250
raise NotImplementedError()
251251

@@ -343,7 +343,7 @@ def created(self) -> datetime.datetime:
343343
raise NotImplementedError()
344344

345345
@property
346-
def labels(self) -> list["IssueLabel"]:
346+
def labels(self) -> Union[list["IssueLabel"], Iterable["IssueLabel"]]:
347347
"""Labels of the issue."""
348348
raise NotImplementedError()
349349

@@ -417,7 +417,7 @@ def get_list(
417417
author: Optional[str] = None,
418418
assignee: Optional[str] = None,
419419
labels: Optional[list[str]] = None,
420-
) -> list["Issue"]:
420+
) -> Union[list["Issue"], Iterable["Issue"]]:
421421
"""
422422
List of issues.
423423
@@ -644,7 +644,7 @@ def created(self) -> datetime.datetime:
644644
raise NotImplementedError()
645645

646646
@property
647-
def labels(self) -> list["PRLabel"]:
647+
def labels(self) -> Union[list["PRLabel"], Iterable["PRLabel"]]:
648648
"""Labels of the pull request."""
649649
raise NotImplementedError()
650650

@@ -761,7 +761,10 @@ def get(project: Any, id: int) -> "PullRequest":
761761
raise NotImplementedError()
762762

763763
@staticmethod
764-
def get_list(project: Any, status: PRStatus = PRStatus.open) -> list["PullRequest"]:
764+
def get_list(
765+
project: Any,
766+
status: PRStatus = PRStatus.open,
767+
) -> Union[list["PullRequest"], Iterable["PullRequest"]]:
765768
"""
766769
List of pull requests.
767770
@@ -841,7 +844,7 @@ def get_comments(
841844
"""
842845
raise NotImplementedError()
843846

844-
def get_all_commits(self) -> list[str]:
847+
def get_all_commits(self) -> Union[list[str], Iterable[str]]:
845848
"""
846849
Returns:
847850
List of commit hashes of commits in pull request.
@@ -925,7 +928,7 @@ def add_label(self, *labels: str) -> None:
925928
"""
926929
raise NotImplementedError()
927930

928-
def get_statuses(self) -> list["CommitFlag"]:
931+
def get_statuses(self) -> Union[list["CommitFlag"], Iterable["CommitFlag"]]:
929932
"""
930933
Returns statuses for latest commit on pull request.
931934
@@ -1014,7 +1017,10 @@ def _from_raw_commit_flag(self) -> None:
10141017
raise NotImplementedError()
10151018

10161019
@staticmethod
1017-
def get(project: Any, commit: str) -> list["CommitFlag"]:
1020+
def get(
1021+
project: Any,
1022+
commit: str,
1023+
) -> Union[list["CommitFlag"], Iterable["CommitFlag"]]:
10181024
"""
10191025
Acquire commit statuses for given commit in the project.
10201026
@@ -1226,7 +1232,7 @@ def get_latest(project: Any) -> Optional["Release"]:
12261232
raise NotImplementedError()
12271233

12281234
@staticmethod
1229-
def get_list(project: Any) -> list["Release"]:
1235+
def get_list(project: Any) -> Union[list["Release"], Iterable["Release"]]:
12301236
"""
12311237
Returns:
12321238
List of the objects that represent releases.
@@ -1388,7 +1394,7 @@ def list_projects(
13881394
user: Optional[str] = None,
13891395
search_pattern: Optional[str] = None,
13901396
language: Optional[str] = None,
1391-
) -> list["GitProject"]:
1397+
) -> Union[list["GitProject"], Iterable["GitProject"]]:
13921398
"""
13931399
List projects for given criteria.
13941400
@@ -1496,7 +1502,7 @@ def has_issues(self) -> bool:
14961502
"""`True` if issues are enabled on the project."""
14971503
raise NotImplementedError()
14981504

1499-
def get_branches(self) -> list[str]:
1505+
def get_branches(self) -> Union[list[str], Iterable[str]]:
15001506
"""
15011507
Returns:
15021508
List with names of branches in the project.
@@ -1508,7 +1514,7 @@ def default_branch(self) -> str:
15081514
"""Default branch (usually `main`, `master` or `trunk`)."""
15091515
raise NotImplementedError()
15101516

1511-
def get_commits(self, ref: Optional[str] = None) -> list[str]:
1517+
def get_commits(self, ref: Optional[str] = None) -> Union[list[str], Iterable[str]]:
15121518
"""
15131519
Get list of commits for the project.
15141520
@@ -1540,7 +1546,7 @@ def get_fork(self, create: bool = True) -> Optional["GitProject"]:
15401546
"""
15411547
raise NotImplementedError()
15421548

1543-
def get_owners(self) -> list[str]:
1549+
def get_owners(self) -> Union[list[str], Iterable[str]]:
15441550
"""
15451551
Returns:
15461552
List of usernames of project owners.
@@ -1639,7 +1645,7 @@ def get_issue_list(
16391645
author: Optional[str] = None,
16401646
assignee: Optional[str] = None,
16411647
labels: Optional[list[str]] = None,
1642-
) -> list["Issue"]:
1648+
) -> Union[list["Issue"], Iterable["Issue"]]:
16431649
"""
16441650
List of issues.
16451651
@@ -1722,7 +1728,10 @@ def create_issue(
17221728
"""
17231729
raise NotImplementedError()
17241730

1725-
def get_pr_list(self, status: PRStatus = PRStatus.open) -> list["PullRequest"]:
1731+
def get_pr_list(
1732+
self,
1733+
status: PRStatus = PRStatus.open,
1734+
) -> Union[list["PullRequest"], Iterable["PullRequest"]]:
17261735
"""
17271736
List of pull requests.
17281737
@@ -1765,7 +1774,7 @@ def get_pr_files_diff(
17651774
"""
17661775
raise NotImplementedError()
17671776

1768-
def get_tags(self) -> list["GitTag"]:
1777+
def get_tags(self) -> Union[list["GitTag"], Iterable["GitTag"]]:
17691778
"""
17701779
Returns:
17711780
List of objects that represent tags.
@@ -1814,7 +1823,7 @@ def get_latest_release(self) -> Optional[Release]:
18141823
"""
18151824
raise NotImplementedError()
18161825

1817-
def get_releases(self) -> list[Release]:
1826+
def get_releases(self) -> Union[list[Release], Iterable[Release]]:
18181827
"""
18191828
Returns:
18201829
List of the objects that represent releases.
@@ -1895,7 +1904,10 @@ def commit_comment(
18951904
"""
18961905
raise NotImplementedError()
18971906

1898-
def get_commit_comments(self, commit: str) -> list[CommitComment]:
1907+
def get_commit_comments(
1908+
self,
1909+
commit: str,
1910+
) -> Union[list[CommitComment], Iterable[CommitComment]]:
18991911
"""
19001912
Get comments for a commit.
19011913
@@ -1947,7 +1959,10 @@ def set_commit_status(
19471959
"""
19481960
raise NotImplementedError()
19491961

1950-
def get_commit_statuses(self, commit: str) -> list[CommitFlag]:
1962+
def get_commit_statuses(
1963+
self,
1964+
commit: str,
1965+
) -> Union[list[CommitFlag], Iterable[CommitFlag]]:
19511966
"""
19521967
Get statuses of the commit.
19531968
@@ -2018,7 +2033,7 @@ def get_files(
20182033
ref: Optional[str] = None,
20192034
filter_regex: Optional[str] = None,
20202035
recursive: bool = False,
2021-
) -> list[str]:
2036+
) -> Union[list[str], Iterable[str]]:
20222037
"""
20232038
Get a list of file paths of the repo.
20242039
@@ -2039,7 +2054,7 @@ def get_files(
20392054
"""
20402055
raise NotImplementedError
20412056

2042-
def get_forks(self) -> Sequence["GitProject"]:
2057+
def get_forks(self) -> Union[Sequence["GitProject"], Iterable["GitProject"]]:
20432058
"""
20442059
Returns:
20452060
All forks of the project.
@@ -2106,14 +2121,14 @@ def get_email(self) -> str:
21062121
"""
21072122
raise NotImplementedError()
21082123

2109-
def get_projects(self) -> Sequence["GitProject"]:
2124+
def get_projects(self) -> Union[Sequence["GitProject"], Iterable["GitProject"]]:
21102125
"""
21112126
Returns:
21122127
Sequence of projects in user's namespace.
21132128
"""
21142129
raise NotImplementedError()
21152130

2116-
def get_forks(self) -> Sequence["GitProject"]:
2131+
def get_forks(self) -> Union[Sequence["GitProject"], Iterable["GitProject"]]:
21172132
"""
21182133
Returns:
21192134
Sequence of forks in user's namespace.

ogr/services/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def search(
7878
filter_regex=filter_regex,
7979
)
8080

81-
def get_statuses(self) -> list[CommitFlag]:
81+
def get_statuses(self) -> Union[list[CommitFlag], Iterable[CommitFlag]]:
8282
commit = self.get_all_commits()[-1]
8383
return self.target_project.get_commit_statuses(commit)
8484

ogr/services/pagure/pull_request.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ def merge(self) -> "PullRequest":
345345
self.__dirty = True
346346
return self
347347

348-
def get_statuses(self) -> list[CommitFlag]:
348+
def get_statuses(self) -> Union[list[CommitFlag], Iterable[CommitFlag]]:
349349
self.__update()
350350
return self.target_project.get_commit_statuses(self._raw_pr["commit_stop"])
351351

0 commit comments

Comments
 (0)