bin/pick: fix issue where None for nomination_type could fail

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>
This commit is contained in:
Dylan Baker 2023-04-20 11:22:42 -07:00 committed by Marge Bot
parent 3f48d84296
commit dd760f8846

View 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