if
statements can be merged PTC-W0048123 if 'Arch Linux' in release:
124 dist = 'arch'
125
126 if dist == '':127 if os.path.exists('/etc/system-release'):
128 release = open('/etc/system-release').read()
129 if 'Amazon Linux AMI' in release:
117 else:
118 dist = pyplatform.dist()[0]
119
120 if dist == '':121 if os.path.exists('/etc/os-release'):
122 release = open('/etc/os-release').read()
123 if 'Arch Linux' in release:
41 context.identity = None
42
43 def handle(self, http_context):
44 if http_context.env['SSL_CLIENT_VALID']: 45 if not self.context.identity:
46 username = http_context.env['SSL_CLIENT_USER']
47 logging.info(
130 self.q_socket_messages.broadcast(resp)
131 if resp.object['type'] == 'http':
132 self.q_http_replies.broadcast(resp)
133 if resp.object['type'] == 'terminate':134 if self.session != self.gateway_middleware:
135 # Not the restricted session, we can disable it
136 self.session.deactivate()
44
45 for _dir in os.listdir(self.path):
46 path = os.path.join(self.path, _dir)
47 if os.path.isdir(path): 48 if os.path.exists(os.path.join(path, 'plugin.yml')):
49 found_plugins.append(path)
50
Nested if
statements can be collapsed into a single if
statement by separating their condition using and
operator.
Merging collapsible if
statements increases the code's readability.
if condition1:
if condition2:
dosomething()
if condition1 and condition2:
dosomething()
DeepSource will not raise this issue when the nested if
statements have comments in between them, as it could be explaining why the nested if
is in place.