maintainers: remove Tuple usage
Avoid 'Tuple[List[str],List[str]]' type by creating a well-defined
NamedTuple of the results of parsing the maintainer list.
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: Ieb7befa2f3d15d7d43a5006057b0626be09d18f6
diff --git a/maintainers/obmc-gerrit b/maintainers/obmc-gerrit
index b666652..c6636e5 100755
--- a/maintainers/obmc-gerrit
+++ b/maintainers/obmc-gerrit
@@ -8,7 +8,8 @@
# it exists).
from obmc import maintainers
-from typing import cast, Callable, List, Optional, Tuple
+from obmc.reviewlist import ReviewList
+from typing import cast, Callable, List, Optional
import argparse
import os
import sh # type: ignore
@@ -19,9 +20,8 @@
def get_reviewers(
root: Optional[str] = None, mname: str = "MAINTAINERS"
-) -> Tuple[List[str], List[str]]:
- maints: List[str] = list()
- reviewers: List[str] = list()
+) -> ReviewList:
+
if not root:
root = git("rev-parse", "--show-toplevel").strip()
@@ -29,7 +29,7 @@
if os.path.exists(mfile):
return maintainers.get_reviewers(mfile)
- return (maints, reviewers)
+ return ReviewList()
def gerrit_refspec_args(
@@ -48,8 +48,8 @@
def decorate_refspec(refspec: str, topic: str) -> str:
- (maintainers, reviewers) = get_reviewers()
- gargs = gerrit_refspec_args(maintainers, reviewers, topic)
+ revlist = get_reviewers()
+ gargs = gerrit_refspec_args(revlist.maintainers, revlist.reviewers, topic)
if not gargs:
return refspec
if "%" in refspec:
@@ -69,8 +69,8 @@
def do_reviewers(args: argparse.Namespace) -> None:
- (maintainers, reviewers) = get_reviewers()
- print(gerrit_refspec_args(maintainers, reviewers))
+ revlist = get_reviewers()
+ print(gerrit_refspec_args(revlist.maintainers, revlist.reviewers))
parser = argparse.ArgumentParser()
diff --git a/maintainers/obmc/maintainers.py b/maintainers/obmc/maintainers.py
index f541e36..1aac9ce 100755
--- a/maintainers/obmc/maintainers.py
+++ b/maintainers/obmc/maintainers.py
@@ -10,7 +10,6 @@
from typing import (
Dict,
NamedTuple,
- Tuple,
Iterator,
Sequence,
Union,
@@ -20,6 +19,7 @@
IO,
)
from pprint import pprint
+from .reviewlist import ReviewList
@unique
@@ -185,21 +185,20 @@
return maintainers
-def get_reviewers(mfile: str) -> Tuple[List[str], List[str]]:
- maintainers: List[str] = list()
- reviewers: List[str] = list()
+def get_reviewers(mfile: str) -> ReviewList:
+ revlist = ReviewList()
with open(mfile) as mstream:
trash_preamble(mstream)
block = parse_block(mstream)
if not block:
- return (maintainers, reviewers)
+ return revlist
mlist = cast(List[Identity], block[LineType.MAINTAINER])
- maintainers.extend(i.email.address for i in mlist)
+ revlist.maintainers.extend(i.email.address for i in mlist)
if LineType.REVIEWER in block:
rlist = cast(List[Identity], block[LineType.REVIEWER])
- reviewers.extend(i.email.address for i in rlist)
- return (maintainers, reviewers)
+ revlist.reviewers.extend(i.email.address for i in rlist)
+ return revlist
def assemble_name(name: str, dst: IO[str]) -> None:
diff --git a/maintainers/obmc/reviewlist.py b/maintainers/obmc/reviewlist.py
new file mode 100644
index 0000000..08df514
--- /dev/null
+++ b/maintainers/obmc/reviewlist.py
@@ -0,0 +1,5 @@
+from typing import List, NamedTuple
+
+class ReviewList(NamedTuple):
+ maintainers: List[str] = list()
+ reviewers: List[str] = list()