[py] Re-add defaults for Chromium kwargs by cgoldberg · Pull Request #16372 · SeleniumHQ/selenium

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
Handle None for optional parameters

To prevent potential runtime errors, assign default string values to
browser_name and vendor_prefix if they are None.

py/selenium/webdriver/chromium/webdriver.py [32-52]

 def __init__(
     self,
     browser_name: Optional[str] = None,
     vendor_prefix: Optional[str] = None,
     options: Optional[ChromiumOptions] = None,
     service: Optional[ChromiumService] = None,
     keep_alive: bool = True,
 ) -> None:
     """Creates a new WebDriver instance of the ChromiumDriver. Starts the
     service and then creates new WebDriver instance of ChromiumDriver.
 
     :Args:
      - browser_name - Browser name used when matching capabilities.
      - vendor_prefix - Company prefix to apply to vendor-specific WebDriver extension commands.
      - options - this takes an instance of ChromiumOptions
      - service - Service object for handling the browser driver if you need to pass extra details
      - keep_alive - Whether to configure ChromiumRemoteConnection to use HTTP keep-alive.
     """
+    browser_name = browser_name or "chromium"
+    vendor_prefix = vendor_prefix or "goog"
 
     self.service = service if service else ChromiumService()
     options = options if options else ChromiumOptions()
  • Apply / Chat
Suggestion importance[1-10]: 8

__

Why: The suggestion correctly identifies a potential runtime error from passing None to downstream logic that expects a string, and provides a sensible fix by assigning default values.

Medium
  • More