Skip to content

Commit 010a2f0

Browse files
committed
Refactor code with the "ruff" Python linter
1 parent f2dc88b commit 010a2f0

File tree

10 files changed

+89
-113
lines changed

10 files changed

+89
-113
lines changed

seleniumbase/behave/behave_sb.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ def get_configured_sb(context):
367367
# Handle: -D variables="{'KEY':'VALUE','KEY2':'VALUE2'}"
368368
if low_key == "variables":
369369
variables = userdata[key]
370-
if variables and type(variables) is str and len(variables) > 0:
370+
if variables and isinstance(variables, str) and len(variables) > 0:
371371
bad_input = False
372372
if (
373373
not variables.startswith("{")
@@ -377,7 +377,7 @@ def get_configured_sb(context):
377377
else:
378378
try:
379379
variables = ast.literal_eval(variables)
380-
if not type(variables) is dict:
380+
if not isinstance(variables, dict):
381381
bad_input = True
382382
except Exception:
383383
bad_input = True

seleniumbase/console_scripts/sb_print.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def main():
213213
first_paren = line.find("(")
214214
line1 = line[:first_paren + 1]
215215
line2 = new_ws + line[first_paren + 1:]
216-
if not ("):") in line2:
216+
if ("):") not in line2:
217217
new_sb_lines.append(line1)
218218
if get_width(line2) + w > console_width:
219219
if line2.count('", "') == 1:
@@ -353,7 +353,7 @@ def main():
353353
new_ws = line[0:whitespace] + " "
354354
line1 = line.split('("')[0] + "("
355355
line2 = new_ws + '"' + line.split('("')[1]
356-
if not ("):") in line2:
356+
if ("):") not in line2:
357357
new_sb_lines.append(line1)
358358
if get_width(line2) + w > console_width:
359359
if line2.count('" in self.') == 1:
@@ -382,7 +382,7 @@ def main():
382382
new_ws = line[0:whitespace] + " "
383383
line1 = line.split("('")[0] + "("
384384
line2 = new_ws + "'" + line.split("('")[1]
385-
if not ("):") in line2:
385+
if ("):") not in line2:
386386
new_sb_lines.append(line1)
387387
if get_width(line2) + w > console_width:
388388
if line2.count("' in self.") == 1:
@@ -444,7 +444,7 @@ def main():
444444
continue
445445
new_sb_lines.append(line2)
446446
continue
447-
if line.count("(self.") == 1 and not ("):") in line:
447+
if line.count("(self.") == 1 and ("):") not in line:
448448
whitespace = line_length2 - len(line.lstrip())
449449
new_ws = line[0:whitespace] + " "
450450
line1 = line.split("(self.")[0] + "("
@@ -500,7 +500,7 @@ def main():
500500
else:
501501
new_sb_lines.append(line2)
502502
continue
503-
if line.count(" % ") == 1 and not ("):") in line:
503+
if line.count(" % ") == 1 and ("):") not in line:
504504
whitespace = line_length2 - len(line.lstrip())
505505
new_ws = line[0:whitespace] + " "
506506
line1 = line.split(" % ")[0] + " \\"
@@ -509,7 +509,7 @@ def main():
509509
new_sb_lines.append(line1)
510510
new_sb_lines.append(line2)
511511
continue
512-
if line.count(" = ") == 1 and not (" # ") in line:
512+
if line.count(" = ") == 1 and (" # ") not in line:
513513
whitespace = line_length2 - len(line.lstrip())
514514
new_ws = line[0:whitespace] + " "
515515
line1 = line.split(" = ")[0] + " = ("

seleniumbase/core/browser_launcher.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -361,9 +361,9 @@ def uc_special_open_if_cf(
361361
driver.switch_to.window(driver.window_handles[-1])
362362
uc_metrics = {}
363363
if (
364-
type(device_width) is int
365-
and type(device_height) is int
366-
and type(device_pixel_ratio) is int
364+
isinstance(device_width, int)
365+
and isinstance(device_height, int)
366+
and isinstance(device_pixel_ratio, int)
367367
):
368368
uc_metrics["width"] = device_width
369369
uc_metrics["height"] = device_height
@@ -847,9 +847,9 @@ def _set_chrome_options(
847847
emulator_settings = {}
848848
device_metrics = {}
849849
if (
850-
type(device_width) is int
851-
and type(device_height) is int
852-
and type(device_pixel_ratio) is int
850+
isinstance(device_width, int)
851+
and isinstance(device_height, int)
852+
and isinstance(device_pixel_ratio, int)
853853
):
854854
device_metrics["width"] = device_width
855855
device_metrics["height"] = device_height
@@ -1389,7 +1389,7 @@ def get_driver(
13891389
headless = True
13901390
if (
13911391
binary_location
1392-
and type(binary_location) is str
1392+
and isinstance(binary_location, str)
13931393
and (
13941394
browser_name == constants.Browser.GOOGLE_CHROME
13951395
or browser_name == constants.Browser.EDGE
@@ -2553,9 +2553,9 @@ def get_local_driver(
25532553
emulator_settings = {}
25542554
device_metrics = {}
25552555
if (
2556-
type(device_width) is int
2557-
and type(device_height) is int
2558-
and type(device_pixel_ratio) is int
2556+
isinstance(device_width, int)
2557+
and isinstance(device_height, int)
2558+
and isinstance(device_pixel_ratio, int)
25592559
):
25602560
device_metrics["width"] = device_width
25612561
device_metrics["height"] = device_height
@@ -3703,9 +3703,9 @@ def get_local_driver(
37033703
if mobile_emulator:
37043704
uc_metrics = {}
37053705
if (
3706-
type(device_width) is int
3707-
and type(device_height) is int
3708-
and type(device_pixel_ratio) is int
3706+
isinstance(device_width, int)
3707+
and isinstance(device_height, int)
3708+
and isinstance(device_pixel_ratio, int)
37093709
):
37103710
uc_metrics["width"] = device_width
37113711
uc_metrics["height"] = device_height

seleniumbase/core/jqc_helper.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,7 @@ def jquery_confirm_text_dialog(driver, message, button=None, options=None):
118118
if not message:
119119
message = ""
120120
if button:
121-
if not type(button) is list and not type(button) is tuple:
122-
raise Exception('"button" should be a (text, color) tuple!')
123-
if len(button) != 2:
121+
if not isinstance(button, (list, tuple)) or len(button) != 2:
124122
raise Exception('"button" should be a (text, color) tuple!')
125123
else:
126124
button = ("Submit", "blue")

0 commit comments

Comments
 (0)