Skip to content

Commit ecbe329

Browse files
committed
Refactor docstrings for clarity and conciseness across multiple files
1 parent 20d02f1 commit ecbe329

21 files changed

+82
-140
lines changed

py/generate.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ class CdpProperty:
216216
deprecated: bool
217217

218218
@property
219-
def py_name(self):
219+
def py_name(self)->str:
220220
''' Get this property's Python name. '''
221221
return snake_case(self.name)
222222

@@ -590,7 +590,7 @@ class CdpCommand:
590590
domain: str
591591

592592
@property
593-
def py_name(self):
593+
def py_name(self) -> str:
594594
''' Get a Python name for this command. '''
595595
return snake_case(self.name)
596596

@@ -794,7 +794,7 @@ class CdpDomain:
794794
events: List[CdpEvent]
795795

796796
@property
797-
def module(self):
797+
def module(self) -> str:
798798
''' The name of the Python module for this CDP domain. '''
799799
return snake_case(self.domain)
800800

py/selenium/webdriver/chromium/options.py

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@ def __init__(self) -> None:
3838

3939
@property
4040
def binary_location(self) -> str:
41-
"""
42-
Returns:
43-
The location of the binary, otherwise an empty string.
44-
"""
41+
"""Returns the location of the binary, otherwise an empty string."""
4542
return self._binary_location
4643

4744
@binary_location.setter
@@ -57,16 +54,12 @@ def binary_location(self, value: str) -> None:
5754

5855
@property
5956
def debugger_address(self) -> Optional[str]:
60-
"""
61-
Returns:
62-
The address of the remote devtools instance.
63-
"""
57+
"""Returns the address of the remote devtools instance."""
6458
return self._debugger_address
6559

6660
@debugger_address.setter
6761
def debugger_address(self, value: str) -> None:
68-
"""Allows you to set the address of the remote devtools instance that
69-
the ChromeDriver instance will try to connect to during an active wait.
62+
"""Set the address of the remote devtools instance for active wait connection.
7063
7164
Args:
7265
value: Address of remote devtools instance if any (hostname[:port]).
@@ -77,10 +70,7 @@ def debugger_address(self, value: str) -> None:
7770

7871
@property
7972
def extensions(self) -> list[str]:
80-
"""
81-
Returns:
82-
A list of encoded extensions that will be loaded.
83-
"""
73+
"""Returns a list of encoded extensions that will be loaded."""
8474

8575
def _decode(file_data: BinaryIO) -> str:
8676
# Should not use base64.encodestring() which inserts newlines every
@@ -96,8 +86,7 @@ def _decode(file_data: BinaryIO) -> str:
9686
return encoded_extensions + self._extensions
9787

9888
def add_extension(self, extension: str) -> None:
99-
"""Adds the path to the extension to a list that will be used to
100-
extract it to the ChromeDriver.
89+
"""Add the path to an extension to be extracted to ChromeDriver.
10190
10291
Args:
10392
extension: Path to the *.crx file.
@@ -112,8 +101,7 @@ def add_extension(self, extension: str) -> None:
112101
raise ValueError("argument can not be null")
113102

114103
def add_encoded_extension(self, extension: str) -> None:
115-
"""Adds Base64 encoded string with extension data to a list that will
116-
be used to extract it to the ChromeDriver.
104+
"""Add Base64-encoded string with extension data to be extracted to ChromeDriver.
117105
118106
Args:
119107
extension: Base64 encoded string with extension data.
@@ -125,10 +113,7 @@ def add_encoded_extension(self, extension: str) -> None:
125113

126114
@property
127115
def experimental_options(self) -> dict:
128-
"""
129-
Returns:
130-
A dictionary of experimental options for chromium.
131-
"""
116+
"""Returns a dictionary of experimental options for chromium."""
132117
return self._experimental_options
133118

134119
def add_experimental_option(self, name: str, value: Union[str, int, dict, list[str]]) -> None:
@@ -142,11 +127,7 @@ def add_experimental_option(self, name: str, value: Union[str, int, dict, list[s
142127

143128
@property
144129
def enable_webextensions(self) -> bool:
145-
"""
146-
Returns:
147-
Whether webextension support is enabled for Chromium-based browsers.
148-
True if webextension support is enabled, False otherwise.
149-
"""
130+
"""Return whether webextension support is enabled for Chromium-based browsers."""
150131
return self._enable_webextensions
151132

152133
@enable_webextensions.setter

py/selenium/webdriver/chromium/webdriver.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@
2626

2727

2828
class ChromiumDriver(RemoteWebDriver):
29-
"""Controls the WebDriver instance of ChromiumDriver and allows you to
30-
drive the browser.
31-
"""
29+
"""Control the WebDriver instance of ChromiumDriver and drive the browser."""
3230

3331
def __init__(
3432
self,
@@ -38,8 +36,7 @@ def __init__(
3836
service: Optional[ChromiumService] = None,
3937
keep_alive: bool = True,
4038
) -> None:
41-
"""Creates a new WebDriver instance of the ChromiumDriver. Starts the
42-
service and then creates new WebDriver instance of ChromiumDriver.
39+
"""Create a new WebDriver instance, start the service, and create new ChromiumDriver instance.
4340
4441
Args:
4542
browser_name: Browser name used when matching capabilities.
@@ -148,17 +145,11 @@ def execute_cdp_cmd(self, cmd: str, cmd_args: dict):
148145
return super().execute_cdp_cmd(cmd, cmd_args)
149146

150147
def get_sinks(self) -> list:
151-
"""
152-
Returns:
153-
A list of sinks available for Cast.
154-
"""
148+
"""Get a list of sinks available for Cast."""
155149
return self.execute("getSinks")["value"]
156150

157151
def get_issue_message(self):
158-
"""
159-
Returns:
160-
An error message when there is any issue in a Cast session.
161-
"""
152+
"""Returns an error message when there is any issue in a Cast session."""
162153
return self.execute("getIssueMessage")["value"]
163154

164155
@property
@@ -186,8 +177,7 @@ def get_log(self, log_type):
186177
return self.execute(Command.GET_LOG, {"type": log_type})["value"]
187178

188179
def set_sink_to_use(self, sink_name: str) -> dict:
189-
"""Sets a specific sink, using its name, as a Cast session receiver
190-
target.
180+
"""Set a specific sink as a Cast session receiver target.
191181
192182
Args:
193183
sink_name: Name of the sink to use as the target.

py/selenium/webdriver/common/driver_finder.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626

2727

2828
class DriverFinder:
29-
"""A Driver finding class responsible for obtaining the correct driver and
30-
associated browser.
29+
"""Find and obtain the correct driver and associated browser.
3130
3231
Args:
3332
service: instance of the driver service class.

py/selenium/webdriver/common/log.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ def import_cdp():
3434

3535

3636
class Log:
37-
"""This class allows access to logging APIs that use the new WebDriver Bidi
38-
protocol.
37+
"""Class for accessing logging APIs using the WebDriver Bidi protocol.
3938
4039
This class is not to be used directly and should be used from the
4140
webdriver base classes.
@@ -95,8 +94,7 @@ async def mutation_events(self) -> AsyncGenerator[dict[str, Any], None]:
9594

9695
@asynccontextmanager
9796
async def add_js_error_listener(self) -> AsyncGenerator[dict[str, Any], None]:
98-
"""Listen for JS errors and when the contextmanager exits check if
99-
there were JS Errors.
97+
"""Listen for JS errors and check if they occurred when the context manager exits.
10098
10199
Example:
102100
async with driver.log.add_js_error_listener() as error:

py/selenium/webdriver/common/options.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ def __set__(self, obj, value):
143143

144144

145145
class _ProxyDescriptor:
146-
"""
146+
"""Descriptor for proxy property access.
147+
147148
Returns:
148149
Proxy if set, otherwise None.
149150
"""
@@ -379,9 +380,7 @@ def default_capabilities(self):
379380
"""Return minimal capabilities necessary as a dictionary."""
380381

381382
def ignore_local_proxy_environment_variables(self) -> None:
382-
"""By calling this you will ignore HTTP_PROXY and HTTPS_PROXY from
383-
being picked up and used.
384-
"""
383+
"""Ignore HTTP_PROXY and HTTPS_PROXY environment variables."""
385384
self._ignore_local_proxy = True
386385

387386

@@ -396,7 +395,8 @@ def __init__(self) -> None:
396395

397396
@property
398397
def arguments(self):
399-
"""
398+
"""Get a list of arguments needed for the browser.
399+
400400
Returns:
401401
A list of arguments needed for the browser.
402402
"""
@@ -414,8 +414,9 @@ def add_argument(self, argument: str) -> None:
414414
raise ValueError("argument can not be null")
415415

416416
def ignore_local_proxy_environment_variables(self) -> None:
417-
"""By calling this you will ignore HTTP_PROXY and HTTPS_PROXY from
418-
being picked up and used.
417+
"""Ignore HTTP_PROXY and HTTPS_PROXY environment variables.
418+
419+
This method is deprecated; use a Proxy instance with ProxyType.DIRECT instead.
419420
"""
420421
warnings.warn(
421422
"using ignore_local_proxy_environment_variables in Options has been deprecated, "

py/selenium/webdriver/common/print_page_options.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,8 @@ def __init__(self) -> None:
335335
self._margin: _MarginOpts = {}
336336

337337
def to_dict(self) -> _PrintOpts:
338-
"""
338+
"""Get a dictionary of the configured print options.
339+
339340
Returns:
340341
A hash of print options configured.
341342
"""

py/selenium/webdriver/common/proxy.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,7 @@ def __set__(self, obj, value):
8080

8181

8282
class Proxy:
83-
"""Proxy contains information about proxy type and necessary proxy
84-
settings.
85-
"""
83+
"""Proxy configuration containing proxy type and necessary proxy settings."""
8684

8785
proxyType = ProxyType.UNSPECIFIED
8886
autodetect = False

py/selenium/webdriver/common/service.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@
3737

3838

3939
class Service(ABC):
40-
"""The abstract base class for all service objects. Services typically
41-
launch a child program in a new process as an interim process to
40+
"""Abstract base class for all service objects that manage driver processes.
41+
42+
Services typically launch a child program in a new process as an interim process to
4243
communicate with a browser.
4344
4445
Args:
@@ -123,15 +124,15 @@ def assert_process_still_running(self) -> None:
123124
raise WebDriverException(f"Service {self._path} unexpectedly exited. Status code was: {return_code}")
124125

125126
def is_connectable(self) -> bool:
126-
"""Establishes a socket connection to determine if the service running
127-
on the port is accessible.
127+
"""Establish a socket connection to determine if the service is accessible.
128+
129+
Returns:
130+
True if the service is connectable on the configured port, False otherwise.
128131
"""
129132
return utils.is_connectable(self.port)
130133

131134
def send_remote_shutdown_command(self) -> None:
132-
"""Dispatch an HTTP request to the shutdown endpoint for the service in
133-
an attempt to stop it.
134-
"""
135+
"""Dispatch an HTTP request to the shutdown endpoint to stop the service."""
135136
try:
136137
request.urlopen(f"{self.service_url}/shutdown")
137138
except URLError:

py/selenium/webdriver/common/utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,7 @@ def is_url_connectable(
138138
host: Optional[str] = "127.0.0.1",
139139
scheme: Optional[str] = "http",
140140
) -> bool:
141-
"""Sends a request to the HTTP server at the /status endpoint to see if it
142-
responds successfully.
141+
"""Send a request to the HTTP server at the /status endpoint to verify connectivity.
143142
144143
Args:
145144
port: port number

0 commit comments

Comments
 (0)