Skip to content

Commit

Permalink
Performance Improvements in conditionals
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Machinexa2 authored Dec 10, 2020
1 parent 07cd99c commit de38e8d
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions py/selenium/webdriver/firefox/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __init__(self):
self.level = None

def to_capabilities(self):
if self.level is not None:
if self.level:
return {"log": {"level": self.level}}
return {}

Expand Down Expand Up @@ -132,7 +132,7 @@ def headless(self, value):
Args:
value: boolean value indicating to set the headless option
"""
if value is True:
if value: # is True or == True can be written as bool(variablename), so
self._arguments.append('-headless')
elif '-headless' in self._arguments:
self._arguments.remove('-headless')
Expand All @@ -159,20 +159,20 @@ def to_capabilities(self):
caps = self._caps
opts = {}

if self._binary is not None:
if self._binary:
opts["binary"] = self._binary._start_cmd
if len(self._preferences) > 0:
if self._preferences:
opts["prefs"] = self._preferences
if self._proxy is not None:
if self._proxy:
self._proxy.add_to_capabilities(caps)
if self._profile is not None:
if self._profile:
opts["profile"] = self._profile.encoded
if len(self._arguments) > 0:
if self._arguments:
opts["args"] = self._arguments

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

if len(opts) > 0:
if opts:
caps[Options.KEY] = opts

return caps
Expand Down

0 comments on commit de38e8d

Please sign in to comment.