bin/pick: fix issue where None for nomination_type could fail
authorDylan Baker <dylan.c.baker@intel.com>
Thu, 20 Apr 2023 18:22:42 +0000 (11:22 -0700)
committerMarge Bot <emma+marge@anholt.net>
Thu, 15 Jun 2023 22:37:31 +0000 (22:37 +0000)
We have an assumption it's never None, so use a special value in the
Enum instead.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23472>

bin/pick/core.py

index 766749c..a097dab 100644 (file)
@@ -40,7 +40,7 @@ if typing.TYPE_CHECKING:
         sha: str
         description: str
         nominated: bool
-        nomination_type: typing.Optional[int]
+        nomination_type: int
         resolution: typing.Optional[int]
         main_sha: typing.Optional[str]
         because_sha: typing.Optional[str]
@@ -71,6 +71,7 @@ class NominationType(enum.Enum):
     CC = 0
     FIXES = 1
     REVERT = 2
+    NONE = 3
 
 
 @enum.unique
@@ -116,15 +117,14 @@ class Commit:
     sha: str = attr.ib()
     description: str = attr.ib()
     nominated: bool = attr.ib(False)
-    nomination_type: typing.Optional[NominationType] = attr.ib(None)
+    nomination_type: NominationType = attr.ib(NominationType.NONE)
     resolution: Resolution = attr.ib(Resolution.UNRESOLVED)
     main_sha: typing.Optional[str] = attr.ib(None)
     because_sha: typing.Optional[str] = attr.ib(None)
 
     def to_json(self) -> 'CommitDict':
         d: typing.Dict[str, typing.Any] = attr.asdict(self)
-        if self.nomination_type is not None:
-            d['nomination_type'] = self.nomination_type.value
+        d['nomination_type'] = self.nomination_type.value
         if self.resolution is not None:
             d['resolution'] = self.resolution.value
         return typing.cast('CommitDict', d)
@@ -132,8 +132,7 @@ class Commit:
     @classmethod
     def from_json(cls, data: 'CommitDict') -> 'Commit':
         c = cls(data['sha'], data['description'], data['nominated'], main_sha=data['main_sha'], because_sha=data['because_sha'])
-        if data['nomination_type'] is not None:
-            c.nomination_type = NominationType(data['nomination_type'])
+        c.nomination_type = NominationType(data['nomination_type'])
         if data['resolution'] is not None:
             c.resolution = Resolution(data['resolution'])
         return c