Skip to content

Commit de38e8d

Browse files
author
Machinexa2
authored
Performance Improvements in conditionals
1. Faster way of checking if dictionary / list is empty or not, not using len() 2. variablename != None, or bool(variablename) are same so replace is not None, infact bool() is isnt required in if statement
1 parent 07cd99c commit de38e8d

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

py/selenium/webdriver/firefox/options.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def __init__(self):
2727
self.level = None
2828

2929
def to_capabilities(self):
30-
if self.level is not None:
30+
if self.level:
3131
return {"log": {"level": self.level}}
3232
return {}
3333

@@ -132,7 +132,7 @@ def headless(self, value):
132132
Args:
133133
value: boolean value indicating to set the headless option
134134
"""
135-
if value is True:
135+
if value: # is True or == True can be written as bool(variablename), so
136136
self._arguments.append('-headless')
137137
elif '-headless' in self._arguments:
138138
self._arguments.remove('-headless')
@@ -159,20 +159,20 @@ def to_capabilities(self):
159159
caps = self._caps
160160
opts = {}
161161

162-
if self._binary is not None:
162+
if self._binary:
163163
opts["binary"] = self._binary._start_cmd
164-
if len(self._preferences) > 0:
164+
if self._preferences:
165165
opts["prefs"] = self._preferences
166-
if self._proxy is not None:
166+
if self._proxy:
167167
self._proxy.add_to_capabilities(caps)
168-
if self._profile is not None:
168+
if self._profile:
169169
opts["profile"] = self._profile.encoded
170-
if len(self._arguments) > 0:
170+
if self._arguments:
171171
opts["args"] = self._arguments
172172

173173
opts.update(self.log.to_capabilities())
174174

175-
if len(opts) > 0:
175+
if opts:
176176
caps[Options.KEY] = opts
177177

178178
return caps

0 commit comments

Comments
 (0)