Skip to content

Commit ff55efd

Browse files
[py] Correct type annotations of default-None params (#15341)
Co-authored-by: Corey Goldberg <[email protected]>
1 parent 7959e05 commit ff55efd

22 files changed

+62
-44
lines changed

py/selenium/webdriver/chrome/service.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ class Service(service.ChromiumService):
3737

3838
def __init__(
3939
self,
40-
executable_path=None,
40+
executable_path: Optional[str] = None,
4141
port: int = 0,
4242
service_args: Optional[List[str]] = None,
43-
log_output: SubprocessStdAlias = None,
43+
log_output: Optional[SubprocessStdAlias] = None,
4444
env: Optional[Mapping[str, str]] = None,
4545
**kwargs,
4646
) -> None:

py/selenium/webdriver/chrome/webdriver.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18+
from typing import Optional
19+
1820
from selenium.webdriver.chromium.webdriver import ChromiumDriver
1921
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
2022

@@ -27,8 +29,8 @@ class WebDriver(ChromiumDriver):
2729

2830
def __init__(
2931
self,
30-
options: Options = None,
31-
service: Service = None,
32+
options: Optional[Options] = None,
33+
service: Optional[Service] = None,
3234
keep_alive: bool = True,
3335
) -> None:
3436
"""Creates a new instance of the chrome driver. Starts the service and

py/selenium/webdriver/chromium/service.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ class ChromiumService(service.Service):
3737

3838
def __init__(
3939
self,
40-
executable_path: str = None,
40+
executable_path: Optional[str] = None,
4141
port: int = 0,
4242
service_args: Optional[List[str]] = None,
43-
log_output: SubprocessStdAlias = None,
43+
log_output: Optional[SubprocessStdAlias] = None,
4444
env: Optional[Mapping[str, str]] = None,
45-
driver_path_env_key: str = None,
45+
driver_path_env_key: Optional[str] = None,
4646
**kwargs,
4747
) -> None:
4848
self.service_args = service_args or []

py/selenium/webdriver/chromium/webdriver.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18+
from typing import Optional
19+
1820
from selenium.webdriver.chromium.remote_connection import ChromiumRemoteConnection
1921
from selenium.webdriver.common.driver_finder import DriverFinder
2022
from selenium.webdriver.common.options import ArgOptions
@@ -29,10 +31,10 @@ class ChromiumDriver(RemoteWebDriver):
2931

3032
def __init__(
3133
self,
32-
browser_name: str = None,
33-
vendor_prefix: str = None,
34+
browser_name: Optional[str] = None,
35+
vendor_prefix: Optional[str] = None,
3436
options: ArgOptions = ArgOptions(),
35-
service: Service = None,
37+
service: Optional[Service] = None,
3638
keep_alive: bool = True,
3739
) -> None:
3840
"""Creates a new WebDriver instance of the ChromiumDriver. Starts the

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

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

2727
class KeyActions(Interaction):
2828
def __init__(self, source: KeyInput | PointerInput | WheelInput | None = None) -> None:
29-
if not source:
29+
if source is None:
3030
source = KeyInput(KEY)
3131
self.source = source
3232
super().__init__(source)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def __init__(self, source: Optional[PointerInput] = None, duration: int = 250):
3131
- source: PointerInput instance
3232
- duration: override the default 250 msecs of DEFAULT_MOVE_DURATION in source
3333
"""
34-
if not source:
34+
if source is None:
3535
source = PointerInput(interaction.POINTER_MOUSE, "mouse")
3636
self.source = source
3737
self._duration = duration

py/selenium/webdriver/common/actions/wheel_actions.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@
1414
# KIND, either express or implied. See the License for the
1515
# specific language governing permissions and limitations
1616
# under the License.
17+
18+
from typing import Optional
19+
1720
from .interaction import Interaction
1821
from .wheel_input import WheelInput
1922

2023

2124
class WheelActions(Interaction):
22-
def __init__(self, source: WheelInput = None):
23-
if not source:
25+
def __init__(self, source: Optional[WheelInput] = None):
26+
if source is None:
2427
source = WheelInput("wheel")
2528
super().__init__(source)
2629

py/selenium/webdriver/common/options.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from abc import ABCMeta
2020
from abc import abstractmethod
2121
from enum import Enum
22+
from typing import List
2223
from typing import Optional
2324

2425
from selenium.common.exceptions import InvalidArgumentException
@@ -475,14 +476,14 @@ class ArgOptions(BaseOptions):
475476

476477
def __init__(self) -> None:
477478
super().__init__()
478-
self._arguments = []
479+
self._arguments: List[str] = []
479480

480481
@property
481482
def arguments(self):
482483
""":Returns: A list of arguments needed for the browser."""
483484
return self._arguments
484485

485-
def add_argument(self, argument) -> None:
486+
def add_argument(self, argument: str) -> None:
486487
"""Adds an argument to the list.
487488
488489
:Args:

py/selenium/webdriver/common/service.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ class Service(ABC):
5555

5656
def __init__(
5757
self,
58-
executable_path: str = None,
58+
executable_path: Optional[str] = None,
5959
port: int = 0,
60-
log_output: SubprocessStdAlias = None,
60+
log_output: Optional[SubprocessStdAlias] = None,
6161
env: Optional[Mapping[Any, Any]] = None,
62-
driver_path_env_key: str = None,
62+
driver_path_env_key: Optional[str] = None,
6363
**kwargs,
6464
) -> None:
6565
if isinstance(log_output, str):

py/selenium/webdriver/edge/service.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ class Service(service.ChromiumService):
3737

3838
def __init__(
3939
self,
40-
executable_path: str = None,
40+
executable_path: Optional[str] = None,
4141
port: int = 0,
42-
log_output: SubprocessStdAlias = None,
42+
log_output: Optional[SubprocessStdAlias] = None,
4343
service_args: Optional[List[str]] = None,
4444
env: Optional[Mapping[str, str]] = None,
45-
driver_path_env_key: str = None,
45+
driver_path_env_key: Optional[str] = None,
4646
**kwargs,
4747
) -> None:
4848
self.service_args = service_args or []

py/selenium/webdriver/edge/webdriver.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18+
from typing import Optional
19+
1820
from selenium.webdriver.chromium.webdriver import ChromiumDriver
1921
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
2022

@@ -27,8 +29,8 @@ class WebDriver(ChromiumDriver):
2729

2830
def __init__(
2931
self,
30-
options: Options = None,
31-
service: Service = None,
32+
options: Optional[Options] = None,
33+
service: Optional[Service] = None,
3234
keep_alive: bool = True,
3335
) -> None:
3436
"""Creates a new instance of the edge driver. Starts the service and

py/selenium/webdriver/firefox/service.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ class Service(service.Service):
3737

3838
def __init__(
3939
self,
40-
executable_path: str = None,
40+
executable_path: Optional[str] = None,
4141
port: int = 0,
4242
service_args: Optional[List[str]] = None,
43-
log_output: SubprocessStdAlias = None,
43+
log_output: Optional[SubprocessStdAlias] = None,
4444
env: Optional[Mapping[str, str]] = None,
45-
driver_path_env_key: str = None,
45+
driver_path_env_key: Optional[str] = None,
4646
**kwargs,
4747
) -> None:
4848
self.service_args = service_args or []

py/selenium/webdriver/firefox/webdriver.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import zipfile
2121
from contextlib import contextmanager
2222
from io import BytesIO
23+
from typing import Optional
2324

2425
from selenium.webdriver.common.driver_finder import DriverFinder
2526
from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver
@@ -37,8 +38,8 @@ class WebDriver(RemoteWebDriver):
3738

3839
def __init__(
3940
self,
40-
options: Options = None,
41-
service: Service = None,
41+
options: Optional[Options] = None,
42+
service: Optional[Service] = None,
4243
keep_alive: bool = True,
4344
) -> None:
4445
"""Creates a new instance of the Firefox driver. Starts the service and

py/selenium/webdriver/ie/service.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ class Service(service.Service):
2626

2727
def __init__(
2828
self,
29-
executable_path: str = None,
29+
executable_path: Optional[str] = None,
3030
port: int = 0,
3131
host: Optional[str] = None,
3232
service_args: Optional[List[str]] = None,
3333
log_level: Optional[str] = None,
34-
log_output: SubprocessStdAlias = None,
35-
driver_path_env_key: str = None,
34+
log_output: Optional[SubprocessStdAlias] = None,
35+
driver_path_env_key: Optional[str] = None,
3636
**kwargs,
3737
) -> None:
3838
"""Creates a new instance of the Service.

py/selenium/webdriver/ie/webdriver.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18+
from typing import Optional
19+
1820
from selenium.webdriver.common.driver_finder import DriverFinder
1921
from selenium.webdriver.remote.client_config import ClientConfig
2022
from selenium.webdriver.remote.remote_connection import RemoteConnection
@@ -30,8 +32,8 @@ class WebDriver(RemoteWebDriver):
3032

3133
def __init__(
3234
self,
33-
options: Options = None,
34-
service: Service = None,
35+
options: Optional[Options] = None,
36+
service: Optional[Service] = None,
3537
keep_alive: bool = True,
3638
) -> None:
3739
"""Creates a new instance of the Ie driver.

py/selenium/webdriver/remote/remote_connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ class RemoteConnection:
154154

155155
_timeout = socket.getdefaulttimeout()
156156
_ca_certs = os.getenv("REQUESTS_CA_BUNDLE") if "REQUESTS_CA_BUNDLE" in os.environ else certifi.where()
157-
_client_config: ClientConfig = None
157+
_client_config: Optional[ClientConfig] = None
158158

159159
system = platform.system().lower()
160160
if system == "darwin":

py/selenium/webdriver/remote/webdriver.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
from contextlib import asynccontextmanager
3333
from contextlib import contextmanager
3434
from importlib import import_module
35+
from typing import Any
3536
from typing import Dict
3637
from typing import List
3738
from typing import Optional
@@ -422,7 +423,7 @@ def execute_cdp_cmd(self, cmd: str, cmd_args: dict):
422423
"""
423424
return self.execute("executeCdpCommand", {"cmd": cmd, "params": cmd_args})["value"]
424425

425-
def execute(self, driver_command: str, params: dict = None) -> dict:
426+
def execute(self, driver_command: str, params: Optional[dict[str, Any]] = None) -> dict[str, Any]:
426427
"""Sends a command to be executed by a command.CommandExecutor.
427428
428429
Parameters:
@@ -518,7 +519,7 @@ def get_pinned_scripts(self) -> List[str]:
518519
"""
519520
return list(self.pinned_scripts)
520521

521-
def execute_script(self, script, *args):
522+
def execute_script(self, script: str, *args):
522523
"""Synchronously Executes JavaScript in the current window/frame.
523524
524525
Parameters:

py/selenium/webdriver/safari/service.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ class Service(service.Service):
3737

3838
def __init__(
3939
self,
40-
executable_path: str = None,
40+
executable_path: Optional[str] = None,
4141
port: int = 0,
4242
service_args: Optional[List[str]] = None,
4343
env: Optional[Mapping[str, str]] = None,
4444
reuse_service=False,
4545
enable_logging: bool = False,
46-
driver_path_env_key: str = None,
46+
driver_path_env_key: Optional[str] = None,
4747
**kwargs,
4848
) -> None:
4949
self.service_args = service_args or []

py/selenium/webdriver/safari/webdriver.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18+
from typing import Optional
19+
1820
from selenium.common.exceptions import WebDriverException
1921
from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver
2022

@@ -30,8 +32,8 @@ class WebDriver(RemoteWebDriver):
3032
def __init__(
3133
self,
3234
keep_alive=True,
33-
options: Options = None,
34-
service: Service = None,
35+
options: Optional[Options] = None,
36+
service: Optional[Service] = None,
3537
) -> None:
3638
"""Creates a new Safari driver instance and launches or finds a running
3739
safaridriver service.

py/selenium/webdriver/support/event_firing_webdriver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def back(self) -> None:
8989
def forward(self) -> None:
9090
self._dispatch("navigate_forward", (self._driver,), "forward", ())
9191

92-
def execute_script(self, script, *args):
92+
def execute_script(self, script: str, *args):
9393
unwrapped_args = (script,) + self._unwrap_element_args(args)
9494
return self._dispatch("execute_script", (script, self._driver), "execute_script", unwrapped_args)
9595

py/selenium/webdriver/webkitgtk/webdriver.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
# under the License.
1717

1818
import http.client as http_client
19+
from typing import Optional
1920

2021
from selenium.webdriver.common.driver_finder import DriverFinder
2122
from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver
@@ -30,7 +31,7 @@ class WebDriver(RemoteWebDriver):
3031
def __init__(
3132
self,
3233
options=None,
33-
service: Service = None,
34+
service: Optional[Service] = None,
3435
):
3536
"""Creates a new instance of the WebKitGTK driver.
3637

py/selenium/webdriver/wpewebkit/webdriver.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
# under the License.
1717

1818
import http.client as http_client
19+
from typing import Optional
1920

2021
from selenium.webdriver.common.driver_finder import DriverFinder
2122
from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver
@@ -30,7 +31,7 @@ class WebDriver(RemoteWebDriver):
3031
def __init__(
3132
self,
3233
options=None,
33-
service: Service = None,
34+
service: Optional[Service] = None,
3435
):
3536
"""Creates a new instance of the WPEWebKit driver.
3637

0 commit comments

Comments
 (0)