Skip to content

Commit a362c84

Browse files
committed
fix: simplifying if statements for returning bools (anti-pattern)
1 parent edd3877 commit a362c84

File tree

2 files changed

+8
-26
lines changed

2 files changed

+8
-26
lines changed

src/DIRAC/ConfigurationSystem/private/ConfigurationData.py

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -249,17 +249,11 @@ def mergingEnabled(self):
249249

250250
def getAutoPublish(self):
251251
value = self.extractOptionFromCFG("%s/AutoPublish" % self.configurationPath, self.localCFG)
252-
if value and value.lower() in ("no", "false", "n"):
253-
return False
254-
else:
255-
return True
252+
return not bool(value and value.lower() in ("no", "false", "n"))
256253

257254
def getAutoSlaveSync(self):
258255
value = self.extractOptionFromCFG("%s/AutoSlaveSync" % self.configurationPath, self.localCFG)
259-
if value and value.lower() in ("no", "false", "n"):
260-
return False
261-
else:
262-
return True
256+
return not bool(value and value.lower() in ("no", "false", "n"))
263257

264258
def getServers(self):
265259
return list(self.remoteServerList)
@@ -288,10 +282,7 @@ def getCompressedData(self):
288282

289283
def isMaster(self):
290284
value = self.extractOptionFromCFG("%s/Master" % self.configurationPath, self.localCFG)
291-
if value and value.lower() in ("yes", "true", "y"):
292-
return True
293-
else:
294-
return False
285+
return bool(value and value.lower() in ("yes", "true", "y"))
295286

296287
def getServicesPath(self):
297288
return "/Services"
@@ -304,15 +295,11 @@ def isService(self):
304295

305296
def useServerCertificate(self):
306297
value = self.extractOptionFromCFG("/DIRAC/Security/UseServerCertificate")
307-
if value and value.lower() in ("y", "yes", "true"):
308-
return True
309-
return False
298+
return bool(value and value.lower() in ("yes", "true", "y"))
310299

311300
def skipCACheck(self):
312301
value = self.extractOptionFromCFG("/DIRAC/Security/SkipCAChecks")
313-
if value and value.lower() in ("y", "yes", "true"):
314-
return True
315-
return False
302+
return bool(value and value.lower() in ("yes", "true", "y"))
316303

317304
def dumpLocalCFGToFile(self, fileName):
318305
try:

src/DIRAC/DataManagementSystem/Client/CmdDirCompletion/DirectoryCompletion.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,13 @@ def parse_text_line(self, text, line, cwd):
4444

4545
# check absolute path
4646
def check_absolute(self, path):
47-
if path.startswith(self.fs.seq):
48-
return True
49-
else:
50-
return False
47+
return path.startswith(self.fs.seq)
5148

5249
# generate absolute path
5350
def generate_absolute(self, path, cwd):
5451
if self.check_absolute(path):
55-
pass
56-
else:
57-
path = os.path.join(cwd, path)
58-
return path
52+
return path
53+
return os.path.join(cwd, path)
5954

6055
# get the parent directory or the current directory
6156
# Using the last char "/" to determine

0 commit comments

Comments
 (0)