commit: a387219c4bdc1510e7958193203fcd29acf6c173
Author: Kenneth Raplee <kenrap <AT> kennethraplee <DOT> com>
AuthorDate: Sat Apr 2 01:16:57 2022 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Mon Apr 4 19:04:36 2022 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=a387219c
Return boolean expressions instead of branching
Signed-off-by: Kenneth Raplee <kenrap <AT> kennethraplee.com>
Signed-off-by: Sam James <sam <AT> gentoo.org>
lib/portage/manifest.py | 14 ++++++--------
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):