diff options
author | Kenneth Raplee <kenrap@kennethraplee.com> | 2022-04-01 18:16:57 -0700 |
---|---|---|
committer | Sam James <sam@gentoo.org> | 2022-04-04 20:04:36 +0100 |
commit | a387219c4bdc1510e7958193203fcd29acf6c173 (patch) | |
tree | 072ed6f4f43fc5bb195cdb576961414f03dff42c | |
parent | Simplify with declarative programming (diff) | |
download | portage-a387219c4bdc1510e7958193203fcd29acf6c173.tar.gz portage-a387219c4bdc1510e7958193203fcd29acf6c173.tar.bz2 portage-a387219c4bdc1510e7958193203fcd29acf6c173.zip |
Return boolean expressions instead of branching
Signed-off-by: Kenneth Raplee <kenrap@kennethraplee.com>
Signed-off-by: Sam James <sam@gentoo.org>
-rw-r--r-- | lib/portage/manifest.py | 14 | ||||
-rw-r--r-- | lib/portage/news.py | 22 |
2 files changed, 14 insertions, 22 deletions
diff --git a/lib/portage/manifest.py b/lib/portage/manifest.py index ff166faa8..4eb6dc18c 100644 --- a/lib/portage/manifest.py +++ b/lib/portage/manifest.py @@ -112,14 +112,12 @@ class Manifest2Entry(ManifestEntry): return f"{myline} {with_hashes}" def __eq__(self, other): - if ( - not isinstance(other, Manifest2Entry) - or self.type != other.type - or self.name != other.name - or self.hashes != other.hashes - ): - return False - return True + return ( + isinstance(other, Manifest2Entry) + and self.type == other.type + and self.name == other.name + and self.hashes == other.hashes + ) def __ne__(self, other): return not self.__eq__(other) diff --git a/lib/portage/news.py b/lib/portage/news.py index 9f373d3d7..801edb68c 100644 --- a/lib/portage/news.py +++ b/lib/portage/news.py @@ -382,13 +382,12 @@ class DisplayProfileRestriction(DisplayRestriction): self.format = news_format def isValid(self): - if fnmatch.fnmatch(self.format, "1.*") and "*" in self.profile: - return False - if fnmatch.fnmatch(self.format, "2.*") and not _valid_profile_RE.match( - self.profile - ): - return False - return True + return ( + not fnmatch.fnmatch(self.format, "1.*") + or "*" not in self.profile + and not fnmatch.fnmatch(self.format, "2.*") + or _valid_profile_RE.match(self.profile) + ) def checkRestriction(self, **kwargs): if fnmatch.fnmatch(self.format, "2.*") and self.profile.endswith("/*"): @@ -407,9 +406,7 @@ class DisplayKeywordRestriction(DisplayRestriction): self.format = news_format def checkRestriction(self, **kwargs): - if kwargs["config"].get("ARCH", "") == self.keyword: - return True - return False + return kwargs["config"].get("ARCH", "") == self.keyword class DisplayInstalledRestriction(DisplayRestriction): @@ -430,10 +427,7 @@ class DisplayInstalledRestriction(DisplayRestriction): return isvalidatom(self.atom) def checkRestriction(self, **kwargs): - vdb = kwargs["vardb"] - if vdb.match(self.atom): - return True - return False + return kwargs["vardb"].match(self.atom) def count_unread_news(portdb, vardb, repos=None, update=True): |