1 |
commit: a387219c4bdc1510e7958193203fcd29acf6c173 |
2 |
Author: Kenneth Raplee <kenrap <AT> kennethraplee <DOT> com> |
3 |
AuthorDate: Sat Apr 2 01:16:57 2022 +0000 |
4 |
Commit: Sam James <sam <AT> gentoo <DOT> org> |
5 |
CommitDate: Mon Apr 4 19:04:36 2022 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=a387219c |
7 |
|
8 |
Return boolean expressions instead of branching |
9 |
|
10 |
Signed-off-by: Kenneth Raplee <kenrap <AT> kennethraplee.com> |
11 |
Signed-off-by: Sam James <sam <AT> gentoo.org> |
12 |
|
13 |
lib/portage/manifest.py | 14 ++++++-------- |
14 |
lib/portage/news.py | 22 ++++++++-------------- |
15 |
2 files changed, 14 insertions(+), 22 deletions(-) |
16 |
|
17 |
diff --git a/lib/portage/manifest.py b/lib/portage/manifest.py |
18 |
index ff166faa8..4eb6dc18c 100644 |
19 |
--- a/lib/portage/manifest.py |
20 |
+++ b/lib/portage/manifest.py |
21 |
@@ -112,14 +112,12 @@ class Manifest2Entry(ManifestEntry): |
22 |
return f"{myline} {with_hashes}" |
23 |
|
24 |
def __eq__(self, other): |
25 |
- if ( |
26 |
- not isinstance(other, Manifest2Entry) |
27 |
- or self.type != other.type |
28 |
- or self.name != other.name |
29 |
- or self.hashes != other.hashes |
30 |
- ): |
31 |
- return False |
32 |
- return True |
33 |
+ return ( |
34 |
+ isinstance(other, Manifest2Entry) |
35 |
+ and self.type == other.type |
36 |
+ and self.name == other.name |
37 |
+ and self.hashes == other.hashes |
38 |
+ ) |
39 |
|
40 |
def __ne__(self, other): |
41 |
return not self.__eq__(other) |
42 |
|
43 |
diff --git a/lib/portage/news.py b/lib/portage/news.py |
44 |
index 9f373d3d7..801edb68c 100644 |
45 |
--- a/lib/portage/news.py |
46 |
+++ b/lib/portage/news.py |
47 |
@@ -382,13 +382,12 @@ class DisplayProfileRestriction(DisplayRestriction): |
48 |
self.format = news_format |
49 |
|
50 |
def isValid(self): |
51 |
- if fnmatch.fnmatch(self.format, "1.*") and "*" in self.profile: |
52 |
- return False |
53 |
- if fnmatch.fnmatch(self.format, "2.*") and not _valid_profile_RE.match( |
54 |
- self.profile |
55 |
- ): |
56 |
- return False |
57 |
- return True |
58 |
+ return ( |
59 |
+ not fnmatch.fnmatch(self.format, "1.*") |
60 |
+ or "*" not in self.profile |
61 |
+ and not fnmatch.fnmatch(self.format, "2.*") |
62 |
+ or _valid_profile_RE.match(self.profile) |
63 |
+ ) |
64 |
|
65 |
def checkRestriction(self, **kwargs): |
66 |
if fnmatch.fnmatch(self.format, "2.*") and self.profile.endswith("/*"): |
67 |
@@ -407,9 +406,7 @@ class DisplayKeywordRestriction(DisplayRestriction): |
68 |
self.format = news_format |
69 |
|
70 |
def checkRestriction(self, **kwargs): |
71 |
- if kwargs["config"].get("ARCH", "") == self.keyword: |
72 |
- return True |
73 |
- return False |
74 |
+ return kwargs["config"].get("ARCH", "") == self.keyword |
75 |
|
76 |
|
77 |
class DisplayInstalledRestriction(DisplayRestriction): |
78 |
@@ -430,10 +427,7 @@ class DisplayInstalledRestriction(DisplayRestriction): |
79 |
return isvalidatom(self.atom) |
80 |
|
81 |
def checkRestriction(self, **kwargs): |
82 |
- vdb = kwargs["vardb"] |
83 |
- if vdb.match(self.atom): |
84 |
- return True |
85 |
- return False |
86 |
+ return kwargs["vardb"].match(self.atom) |
87 |
|
88 |
|
89 |
def count_unread_news(portdb, vardb, repos=None, update=True): |