Skip to content

Commit 0e0194b

Browse files
Machinexa2AutomatedTester
Machinexa2
andauthored
All is None and is not None removal (#8963)
Co-authored-by: machinexa2 <machinexa> Co-authored-by: David Burns <[email protected]>
1 parent 6ac3db6 commit 0e0194b

32 files changed

+96
-98
lines changed

py/selenium/common/exceptions.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ def __init__(self, msg=None, screen=None, stacktrace=None):
3232

3333
def __str__(self):
3434
exception_msg = "Message: %s\n" % self.msg
35-
if self.screen is not None:
35+
if self.screen:
3636
exception_msg += "Screenshot: available via screen\n"
37-
if self.stacktrace is not None:
37+
if self.stacktrace:
3838
stacktrace = "\n".join(self.stacktrace)
3939
exception_msg += "Stacktrace:\n%s" % stacktrace
4040
return exception_msg

py/selenium/webdriver/chrome/webdriver.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def __init__(self, executable_path="chromedriver", port=DEFAULT_PORT,
5858
DeprecationWarning, stacklevel=2)
5959
options = chrome_options
6060

61-
if service is None:
61+
if not service:
6262
service = Service(executable_path, port, service_args, service_log_path)
6363

6464
super(WebDriver, self).__init__(DesiredCapabilities.CHROME['browserName'], "goog",

py/selenium/webdriver/chromium/service.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def __init__(self, executable_path, port=0, service_args=None,
3838
if log_path:
3939
self.service_args.append('--log-path=%s' % log_path)
4040

41-
if start_error_message is None:
41+
if not start_error_message:
4242
raise AttributeError("start_error_message should not be empty")
4343

4444
service.Service.__init__(self, executable_path, port=port, env=env, start_error_message=start_error_message)

py/selenium/webdriver/chromium/webdriver.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def __init__(self, browser_name, vendor_prefix,
4848
- service_log_path - Deprecated: Where to log information from the driver.
4949
- keep_alive - Whether to configure ChromiumRemoteConnection to use HTTP keep-alive.
5050
"""
51-
if desired_capabilities is not None:
51+
if desired_capabilities:
5252
warnings.warn('desired_capabilities has been deprecated, please pass in a Service object',
5353
DeprecationWarning, stacklevel=2)
5454
if port != DEFAULT_PORT:
@@ -60,12 +60,12 @@ def __init__(self, browser_name, vendor_prefix,
6060
DeprecationWarning, stacklevel=2)
6161

6262
_ignore_proxy = None
63-
if options is None:
63+
if not options:
6464
# desired_capabilities stays as passed in
65-
if desired_capabilities is None:
65+
if not desired_capabilities:
6666
desired_capabilities = self.create_options().to_capabilities()
6767
else:
68-
if desired_capabilities is None:
68+
if not desired_capabilities:
6969
desired_capabilities = options.to_capabilities()
7070
else:
7171
desired_capabilities.update(options.to_capabilities())
@@ -74,7 +74,7 @@ def __init__(self, browser_name, vendor_prefix,
7474

7575
self.vendor_prefix = vendor_prefix
7676

77-
if service is None:
77+
if not service:
7878
raise AttributeError('service cannot be None')
7979

8080
self.service = service

py/selenium/webdriver/common/actions/action_builder.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525

2626
class ActionBuilder(object):
2727
def __init__(self, driver, mouse=None, keyboard=None):
28-
if mouse is None:
28+
if not mouse:
2929
mouse = PointerInput(interaction.POINTER_MOUSE, "mouse")
30-
if keyboard is None:
30+
if not keyboard:
3131
keyboard = KeyInput(interaction.KEY)
3232
self.devices = [mouse, keyboard]
3333
self._key_action = KeyActions(keyboard)

py/selenium/webdriver/common/actions/input_device.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class InputDevice(object):
2323
Describes the input device being used for the action.
2424
"""
2525
def __init__(self, name=None):
26-
if name is None:
26+
if not name:
2727
self.name = uuid.uuid4()
2828
else:
2929
self.name = name

py/selenium/webdriver/common/actions/key_actions.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
class KeyActions(Interaction):
2323

2424
def __init__(self, source=None):
25-
if source is None:
25+
if not source:
2626
source = KeyInput(KEY)
2727
self.source = source
2828
super(KeyActions, self).__init__(source)

py/selenium/webdriver/common/actions/pointer_actions.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
class PointerActions(Interaction):
2727

2828
def __init__(self, source=None):
29-
if source is None:
29+
if not source:
3030
source = PointerInput(interaction.POINTER_MOUSE, "mouse")
3131
self.source = source
3232
super(PointerActions, self).__init__(source)
@@ -40,7 +40,7 @@ def pointer_up(self, button=MouseButton.LEFT):
4040
def move_to(self, element, x=None, y=None):
4141
if not isinstance(element, WebElement):
4242
raise AttributeError("move_to requires a WebElement")
43-
if x is not None or y is not None:
43+
if x or y:
4444
el_rect = element.rect
4545
left_offset = el_rect['width'] / 2
4646
top_offset = el_rect['height'] / 2

py/selenium/webdriver/common/actions/pointer_input.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def create_pointer_move(self, duration=DEFAULT_MOVE_DURATION, x=None, y=None, or
3939
action["y"] = y
4040
if isinstance(origin, WebElement):
4141
action["origin"] = {"element-6066-11e4-a52e-4f735466cecf": origin.id}
42-
elif origin is not None:
42+
elif origin:
4343
action["origin"] = origin
4444

4545
self.add_action(action)

py/selenium/webdriver/common/proxy.py

+13-16
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,7 @@ def load(cls, value):
5454
value = str(value).upper()
5555
for attr in dir(cls):
5656
attr_value = getattr(cls, attr)
57-
if isinstance(attr_value, dict) and \
58-
'string' in attr_value and \
59-
attr_value['string'] is not None and \
60-
attr_value['string'] == value:
57+
if isinstance(attr_value, dict) and 'string' in attr_value and attr_value['string'] == value:
6158
return attr_value
6259
raise Exception(f"No proxy type is found for {value}")
6360

@@ -86,28 +83,28 @@ def __init__(self, raw=None):
8683
:Args:
8784
- raw: raw proxy data. If None, default class values are used.
8885
"""
89-
if raw is not None:
90-
if 'proxyType' in raw and raw['proxyType'] is not None:
86+
if raw:
87+
if 'proxyType' in raw and raw['proxyType']:
9188
self.proxy_type = ProxyType.load(raw['proxyType'])
92-
if 'ftpProxy' in raw and raw['ftpProxy'] is not None:
89+
if 'ftpProxy' in raw and raw['ftpProxy']:
9390
self.ftp_proxy = raw['ftpProxy']
94-
if 'httpProxy' in raw and raw['httpProxy'] is not None:
91+
if 'httpProxy' in raw and raw['httpProxy']:
9592
self.http_proxy = raw['httpProxy']
96-
if 'noProxy' in raw and raw['noProxy'] is not None:
93+
if 'noProxy' in raw and raw['noProxy']:
9794
self.no_proxy = raw['noProxy']
98-
if 'proxyAutoconfigUrl' in raw and raw['proxyAutoconfigUrl'] is not None:
95+
if 'proxyAutoconfigUrl' in raw and raw['proxyAutoconfigUrl']:
9996
self.proxy_autoconfig_url = raw['proxyAutoconfigUrl']
100-
if 'sslProxy' in raw and raw['sslProxy'] is not None:
97+
if 'sslProxy' in raw and raw['sslProxy']:
10198
self.sslProxy = raw['sslProxy']
102-
if 'autodetect' in raw and raw['autodetect'] is not None:
99+
if 'autodetect' in raw and raw['autodetect']:
103100
self.auto_detect = raw['autodetect']
104-
if 'socksProxy' in raw and raw['socksProxy'] is not None:
101+
if 'socksProxy' in raw and raw['socksProxy']:
105102
self.socks_proxy = raw['socksProxy']
106-
if 'socksUsername' in raw and raw['socksUsername'] is not None:
103+
if 'socksUsername' in raw and raw['socksUsername']:
107104
self.socks_username = raw['socksUsername']
108-
if 'socksPassword' in raw and raw['socksPassword'] is not None:
105+
if 'socksPassword' in raw and raw['socksPassword']:
109106
self.socks_password = raw['socksPassword']
110-
if 'socksVersion' in raw and raw['socksVersion'] is not None:
107+
if 'socksVersion' in raw and raw['socksVersion']:
111108
self.socks_version = raw['socksVersion']
112109

113110
@property

py/selenium/webdriver/common/service.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def start(self):
109109

110110
def assert_process_still_running(self):
111111
return_code = self.process.poll()
112-
if return_code is not None:
112+
if return_code:
113113
raise WebDriverException(
114114
'Service %s unexpectedly exited. Status code was: %s'
115115
% (self.path, return_code)
@@ -148,7 +148,7 @@ def stop(self):
148148
except Exception:
149149
pass
150150

151-
if self.process is None:
151+
if not self.process:
152152
return
153153

154154
try:

py/selenium/webdriver/common/timeouts.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,19 @@ def script(self, _script):
7777
self._script = self._convert(_script)
7878

7979
def _convert(self, timeout):
80-
if timeout is not None:
80+
if timeout:
8181
if isinstance(timeout, (int, float)):
8282
return int(float(timeout) * 1000)
8383
else:
8484
raise TypeError("Timeouts can only be an int or a float")
8585

8686
def _to_json(self):
8787
timeouts = {}
88-
if self._implicit_wait is not None:
88+
if self._implicit_wait:
8989
timeouts["implicit"] = self._implicit_wait
90-
if self._page_load is not None:
90+
if self._page_load:
9191
timeouts["pageLoad"] = self._page_load
92-
if self._script is not None:
92+
if self._script:
9393
timeouts["script"] = self._script
9494

9595
return timeouts

py/selenium/webdriver/firefox/extension_connection.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ def __init__(self, host, firefox_profile, firefox_binary=None, timeout=30):
3737
HOST = host
3838
timeout = int(timeout)
3939

40-
if self.binary is None:
40+
if not self.binary:
4141
self.binary = FirefoxBinary()
4242

43-
if HOST is None:
43+
if not HOST:
4444
HOST = "127.0.0.1"
4545

4646
PORT = utils.free_port()

py/selenium/webdriver/firefox/firefox_profile.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def __init__(self, profile_directory=None):
6666
FirefoxProfile.DEFAULT_PREFERENCES['mutable'])
6767
self.profile_dir = profile_directory
6868
self.tempfolder = None
69-
if self.profile_dir is None:
69+
if not self.profile_dir:
7070
self.profile_dir = self._create_tempfolder()
7171
else:
7272
self.tempfolder = tempfile.mkdtemp()
@@ -340,14 +340,14 @@ def parse_manifest_json(content):
340340
rdf = get_namespace_id(doc, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#')
341341

342342
description = doc.getElementsByTagName(rdf + 'Description').item(0)
343-
if description is None:
343+
if not description:
344344
description = doc.getElementsByTagName('Description').item(0)
345345
for node in description.childNodes:
346346
# Remove the namespace prefix from the tag for comparison
347347
entry = node.nodeName.replace(em, "")
348348
if entry in details.keys():
349349
details.update({entry: get_text(node)})
350-
if details.get('id') is None:
350+
if not details.get('id'):
351351
for i in range(description.attributes.length):
352352
attribute = description.attributes.item(i)
353353
if attribute.name == em + 'id':
@@ -360,7 +360,7 @@ def parse_manifest_json(content):
360360
details['unpack'] = details['unpack'].lower() == 'true'
361361

362362
# If no ID is set, the add-on is invalid
363-
if details.get('id') is None:
363+
if not details.get('id'):
364364
raise AddonFormatError('Add-on id could not be found.')
365365

366366
return details

py/selenium/webdriver/firefox/service.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ def __init__(self, executable_path, port=0, service_args=None,
4141
in the services' environment.
4242
4343
"""
44-
log_file = open(log_path, "a+") if log_path is not None and log_path != "" else None
44+
#the condition will fail on both "" and on None, so no need of `log_path is not None and log_path != ""`
45+
log_file = open(log_path, "a+") if log_path else None
4546

4647
service.Service.__init__(
4748
self, executable_path, port=port, log_file=log_file, env=env)

py/selenium/webdriver/firefox/webdriver.py

+15-16
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
basestring = str
2121

2222
from base64 import b64decode
23-
import shutil
2423
from shutil import rmtree
2524
import warnings
2625
from contextlib import contextmanager
@@ -104,14 +103,14 @@ def __init__(self, firefox_profile=None, firefox_binary=None,
104103
if executable_path != DEFAULT_EXECUTABLE_PATH:
105104
warnings.warn('executable_path has been deprecated, please pass in a Service object',
106105
DeprecationWarning, stacklevel=2)
107-
if capabilities is not None or desired_capabilities is not None:
106+
if capabilities or desired_capabilities:
108107
warnings.warn('capabilities and desired_capabilities have been deprecated, please pass in a Service object',
109108
DeprecationWarning, stacklevel=2)
110-
if firefox_binary is not None:
109+
if firefox_binary:
111110
warnings.warn('firefox_binary has been deprecated, please pass in a Service object',
112111
DeprecationWarning, stacklevel=2)
113112
self.binary = None
114-
if firefox_profile is not None:
113+
if firefox_profile:
115114
warnings.warn('firefox_profile has been deprecated, please pass in an Options object',
116115
DeprecationWarning, stacklevel=2)
117116
self.profile = None
@@ -124,20 +123,20 @@ def __init__(self, firefox_profile=None, firefox_binary=None,
124123
if service_log_path != DEFAULT_SERVICE_LOG_PATH:
125124
warnings.warn('service_log_path has been deprecated, please pass in a Service object',
126125
DeprecationWarning, stacklevel=2)
127-
if service_args is not None:
126+
if service_args:
128127
warnings.warn('service_args has been deprecated, please pass in a Service object',
129128
DeprecationWarning, stacklevel=2)
130129

131130
self.service = service
132131

133132
# If desired capabilities is set, alias it to capabilities.
134133
# If both are set ignore desired capabilities.
135-
if capabilities is None and desired_capabilities:
134+
if not capabilities and desired_capabilities:
136135
capabilities = desired_capabilities
137136

138-
if capabilities is None:
137+
if not capabilities:
139138
capabilities = DesiredCapabilities.FIREFOX.copy()
140-
if options is None:
139+
if not options:
141140
options = Options()
142141

143142
capabilities = dict(capabilities)
@@ -146,20 +145,20 @@ def __init__(self, firefox_profile=None, firefox_binary=None,
146145
self.binary = capabilities["binary"]
147146

148147
# options overrides capabilities
149-
if options is not None:
150-
if options.binary is not None:
148+
if options:
149+
if options.binary:
151150
self.binary = options.binary
152-
if options.profile is not None:
151+
if options.profile:
153152
self.profile = options.profile
154153

155154
# firefox_binary and firefox_profile
156155
# override options
157-
if firefox_binary is not None:
156+
if firefox_binary:
158157
if isinstance(firefox_binary, basestring):
159158
firefox_binary = FirefoxBinary(firefox_binary)
160159
self.binary = firefox_binary
161160
options.binary = firefox_binary
162-
if firefox_profile is not None:
161+
if firefox_profile:
163162
if isinstance(firefox_profile, basestring):
164163
firefox_profile = FirefoxProfile(firefox_profile)
165164
self.profile = firefox_profile
@@ -171,7 +170,7 @@ def __init__(self, firefox_profile=None, firefox_binary=None,
171170
if capabilities.get("acceptInsecureCerts"):
172171
options.accept_insecure_certs = capabilities.get("acceptInsecureCerts")
173172

174-
if self.service is None:
173+
if not self.service:
175174
self.service = Service(
176175
executable_path,
177176
service_args=service_args,
@@ -204,10 +203,10 @@ def quit(self):
204203
else:
205204
self.binary.kill()
206205

207-
if self.profile is not None:
206+
if self.profile:
208207
try:
209208
rmtree(self.profile.path)
210-
if self.profile.tempfolder is not None:
209+
if self.profile.tempfolder:
211210
rmtree(self.profile.tempfolder)
212211
except Exception as e:
213212
print(str(e))

py/selenium/webdriver/ie/service.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ def __init__(self, executable_path, port=0, host=None, log_level=None, log_file=
3636
- log_file : Target of logging of service, may be "stdout", "stderr" or file path.
3737
Default is "stdout"."""
3838
self.service_args = []
39-
if host is not None:
39+
if host:
4040
self.service_args.append("--host=%s" % host)
41-
if log_level is not None:
41+
if log_level:
4242
self.service_args.append("--log-level=%s" % log_level)
43-
if log_file is not None:
43+
if log_file:
4444
self.service_args.append("--log-file=%s" % log_file)
4545

4646
service.Service.__init__(self, executable_path, port=port,

0 commit comments

Comments
 (0)