SeleniumHQ/selenium · error · TypeError

reuse must be a boolean

Error message

reuse must be a boolean

What it means

Service.reuse_service setter enforces that the value is a bool. Assigning any non-bool (int 0/1, string, None) raises TypeError.

Source

Thrown at py/selenium/webdriver/safari/service.py:79

            **kwargs,
        )

    def command_line_args(self) -> list[str]:
        return ["-p", f"{self.port}"] + self._service_args

    @property
    def service_url(self) -> str:
        """Gets the url of the SafariDriver Service."""
        return f"http://localhost:{self.port}"

    @property
    def reuse_service(self) -> bool:
        return self._reuse_service

    @reuse_service.setter
    def reuse_service(self, reuse: bool) -> None:
        if not isinstance(reuse, bool):
            raise TypeError("reuse must be a boolean")
        self._reuse_service = reuse

    @property
    def service_args(self) -> Sequence[str]:
        """Returns the sequence of service arguments."""
        return self._service_args

    @service_args.setter
    def service_args(self, value: Sequence[str]):
        if isinstance(value, str) or not isinstance(value, Sequence):
            raise TypeError("service_args must be a sequence")
        self._service_args = list(value)

View on GitHub (pinned to aa36b38e69)

Solutions

  1. Assign an actual bool: service.reuse_service = True.
  2. Parse config booleans through a helper that returns a real bool.

Example fix

# before
service.reuse_service = 1

# after
service.reuse_service = True
Defensive patterns

Strategy: type-guard

Type guard

def as_bool(v) -> bool:
    if isinstance(v, bool):
        return v
    raise TypeError("reuse_service requires a bool")

Prevention

When it happens

Trigger: service.reuse_service = 1, service.reuse_service = 'true', or service.reuse_service = None.

Common situations: Config-driven booleans arriving from YAML/env as strings or ints; treating Python truthiness as equivalent to bool.

Related errors


AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14). Data as JSON: /api/errors/27ea325b133dc467. Report an issue: GitHub.