Skip to content

[py] correct type annotations of default-None params #15341

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions py/selenium/webdriver/chrome/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ class Service(service.ChromiumService):

def __init__(
self,
executable_path=None,
executable_path: Optional[str] = None,
port: int = 0,
service_args: Optional[List[str]] = None,
log_output: SubprocessStdAlias = None,
log_output: Optional[SubprocessStdAlias] = None,
env: Optional[Mapping[str, str]] = None,
**kwargs,
) -> None:
Expand Down
6 changes: 4 additions & 2 deletions py/selenium/webdriver/chrome/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# specific language governing permissions and limitations
# under the License.

from typing import Optional

from selenium.webdriver.chromium.webdriver import ChromiumDriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

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

def __init__(
self,
options: Options = None,
service: Service = None,
options: Optional[Options] = None,
service: Optional[Service] = None,
keep_alive: bool = True,
) -> None:
"""Creates a new instance of the chrome driver. Starts the service and
Expand Down
6 changes: 3 additions & 3 deletions py/selenium/webdriver/chromium/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ class ChromiumService(service.Service):

def __init__(
self,
executable_path: str = None,
executable_path: Optional[str] = None,
port: int = 0,
service_args: Optional[List[str]] = None,
log_output: SubprocessStdAlias = None,
log_output: Optional[SubprocessStdAlias] = None,
env: Optional[Mapping[str, str]] = None,
driver_path_env_key: str = None,
driver_path_env_key: Optional[str] = None,
**kwargs,
) -> None:
self.service_args = service_args or []
Expand Down
8 changes: 5 additions & 3 deletions py/selenium/webdriver/chromium/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# specific language governing permissions and limitations
# under the License.

from typing import Optional

from selenium.webdriver.chromium.remote_connection import ChromiumRemoteConnection
from selenium.webdriver.common.driver_finder import DriverFinder
from selenium.webdriver.common.options import ArgOptions
Expand All @@ -28,10 +30,10 @@ class ChromiumDriver(RemoteWebDriver):

def __init__(
self,
browser_name: str = None,
vendor_prefix: str = None,
browser_name: Optional[str] = None,
vendor_prefix: Optional[str] = None,
options: ArgOptions = ArgOptions(),
service: Service = None,
service: Optional[Service] = None,
keep_alive: bool = True,
) -> None:
"""Creates a new WebDriver instance of the ChromiumDriver. Starts the
Expand Down
2 changes: 1 addition & 1 deletion py/selenium/webdriver/common/actions/key_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

class KeyActions(Interaction):
def __init__(self, source: KeyInput | PointerInput | WheelInput | None = None) -> None:
if not source:
if source is None:
source = KeyInput(KEY)
self.source = source
super().__init__(source)
Expand Down
2 changes: 1 addition & 1 deletion py/selenium/webdriver/common/actions/pointer_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def __init__(self, source: Optional[PointerInput] = None, duration: int = 250):
- source: PointerInput instance
- duration: override the default 250 msecs of DEFAULT_MOVE_DURATION in source
"""
if not source:
if source is None:
source = PointerInput(interaction.POINTER_MOUSE, "mouse")
self.source = source
self._duration = duration
Expand Down
7 changes: 5 additions & 2 deletions py/selenium/webdriver/common/actions/wheel_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

from typing import Optional

from .interaction import Interaction
from .wheel_input import WheelInput


class WheelActions(Interaction):
def __init__(self, source: WheelInput = None):
if not source:
def __init__(self, source: Optional[WheelInput] = None):
if source is None:
source = WheelInput("wheel")
super().__init__(source)

Expand Down
5 changes: 3 additions & 2 deletions py/selenium/webdriver/common/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from abc import ABCMeta
from abc import abstractmethod
from enum import Enum
from typing import List
from typing import Optional

from selenium.common.exceptions import InvalidArgumentException
Expand Down Expand Up @@ -497,14 +498,14 @@ class ArgOptions(BaseOptions):

def __init__(self) -> None:
super().__init__()
self._arguments = []
self._arguments: List[str] = []

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

def add_argument(self, argument) -> None:
def add_argument(self, argument: str) -> None:
"""Adds an argument to the list.

:Args:
Expand Down
6 changes: 3 additions & 3 deletions py/selenium/webdriver/common/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ class Service(ABC):

def __init__(
self,
executable_path: str = None,
executable_path: Optional[str] = None,
port: int = 0,
log_output: SubprocessStdAlias = None,
log_output: Optional[SubprocessStdAlias] = None,
env: Optional[Mapping[Any, Any]] = None,
driver_path_env_key: str = None,
driver_path_env_key: Optional[str] = None,
**kwargs,
) -> None:
if isinstance(log_output, str):
Expand Down
6 changes: 3 additions & 3 deletions py/selenium/webdriver/edge/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ class Service(service.ChromiumService):

def __init__(
self,
executable_path: str = None,
executable_path: Optional[str] = None,
port: int = 0,
log_output: SubprocessStdAlias = None,
log_output: Optional[SubprocessStdAlias] = None,
service_args: Optional[List[str]] = None,
env: Optional[Mapping[str, str]] = None,
driver_path_env_key: str = None,
driver_path_env_key: Optional[str] = None,
**kwargs,
) -> None:
self.service_args = service_args or []
Expand Down
6 changes: 4 additions & 2 deletions py/selenium/webdriver/edge/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# specific language governing permissions and limitations
# under the License.

from typing import Optional

from selenium.webdriver.chromium.webdriver import ChromiumDriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

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

def __init__(
self,
options: Options = None,
service: Service = None,
options: Optional[Options] = None,
service: Optional[Service] = None,
keep_alive: bool = True,
) -> None:
"""Creates a new instance of the edge driver. Starts the service and
Expand Down
6 changes: 3 additions & 3 deletions py/selenium/webdriver/firefox/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ class Service(service.Service):

def __init__(
self,
executable_path: str = None,
executable_path: Optional[str] = None,
port: int = 0,
service_args: Optional[List[str]] = None,
log_output: SubprocessStdAlias = None,
log_output: Optional[SubprocessStdAlias] = None,
env: Optional[Mapping[str, str]] = None,
driver_path_env_key: str = None,
driver_path_env_key: Optional[str] = None,
**kwargs,
) -> None:
self.service_args = service_args or []
Expand Down
5 changes: 3 additions & 2 deletions py/selenium/webdriver/firefox/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import zipfile
from contextlib import contextmanager
from io import BytesIO
from typing import Optional

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

def __init__(
self,
options: Options = None,
service: Service = None,
options: Optional[Options] = None,
service: Optional[Service] = None,
keep_alive: bool = True,
) -> None:
"""Creates a new instance of the Firefox driver. Starts the service and
Expand Down
6 changes: 3 additions & 3 deletions py/selenium/webdriver/ie/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ class Service(service.Service):

def __init__(
self,
executable_path: str = None,
executable_path: Optional[str] = None,
port: int = 0,
host: Optional[str] = None,
service_args: Optional[List[str]] = None,
log_level: Optional[str] = None,
log_output: SubprocessStdAlias = None,
driver_path_env_key: str = None,
log_output: Optional[SubprocessStdAlias] = None,
driver_path_env_key: Optional[str] = None,
**kwargs,
) -> None:
"""Creates a new instance of the Service.
Expand Down
6 changes: 4 additions & 2 deletions py/selenium/webdriver/ie/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# specific language governing permissions and limitations
# under the License.

from typing import Optional

from selenium.webdriver.common.driver_finder import DriverFinder
from selenium.webdriver.remote.client_config import ClientConfig
from selenium.webdriver.remote.remote_connection import RemoteConnection
Expand All @@ -30,8 +32,8 @@ class WebDriver(RemoteWebDriver):

def __init__(
self,
options: Options = None,
service: Service = None,
options: Optional[Options] = None,
service: Optional[Service] = None,
keep_alive: bool = True,
) -> None:
"""Creates a new instance of the Ie driver.
Expand Down
2 changes: 1 addition & 1 deletion py/selenium/webdriver/remote/remote_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class RemoteConnection:
else socket.getdefaulttimeout()
)
_ca_certs = os.getenv("REQUESTS_CA_BUNDLE") if "REQUESTS_CA_BUNDLE" in os.environ else certifi.where()
_client_config: ClientConfig = None
_client_config: Optional[ClientConfig] = None

system = platform.system().lower()
if system == "darwin":
Expand Down
5 changes: 3 additions & 2 deletions py/selenium/webdriver/remote/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from contextlib import asynccontextmanager
from contextlib import contextmanager
from importlib import import_module
from typing import Any
from typing import Dict
from typing import List
from typing import Optional
Expand Down Expand Up @@ -401,7 +402,7 @@ def execute_cdp_cmd(self, cmd: str, cmd_args: dict):
"""
return self.execute("executeCdpCommand", {"cmd": cmd, "params": cmd_args})["value"]

def execute(self, driver_command: str, params: dict = None) -> dict:
def execute(self, driver_command: str, params: dict[str, Any]) -> dict[str, Any]:
"""Sends a command to be executed by a command.CommandExecutor.

Parameters:
Expand Down Expand Up @@ -497,7 +498,7 @@ def get_pinned_scripts(self) -> List[str]:
"""
return list(self.pinned_scripts)

def execute_script(self, script, *args):
def execute_script(self, script: str, *args):
"""Synchronously Executes JavaScript in the current window/frame.

Parameters:
Expand Down
4 changes: 2 additions & 2 deletions py/selenium/webdriver/safari/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ class Service(service.Service):

def __init__(
self,
executable_path: str = None,
executable_path: Optional[str] = None,
port: int = 0,
service_args: Optional[List[str]] = None,
env: Optional[Mapping[str, str]] = None,
reuse_service=False,
enable_logging: bool = False,
driver_path_env_key: str = None,
driver_path_env_key: Optional[str] = None,
**kwargs,
) -> None:
self.service_args = service_args or []
Expand Down
6 changes: 4 additions & 2 deletions py/selenium/webdriver/safari/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# specific language governing permissions and limitations
# under the License.

from typing import Optional

from selenium.common.exceptions import WebDriverException
from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver

Expand All @@ -30,8 +32,8 @@ class WebDriver(RemoteWebDriver):
def __init__(
self,
keep_alive=True,
options: Options = None,
service: Service = None,
options: Optional[Options] = None,
service: Optional[Service] = None,
) -> None:
"""Creates a new Safari driver instance and launches or finds a running
safaridriver service.
Expand Down
2 changes: 1 addition & 1 deletion py/selenium/webdriver/support/event_firing_webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def back(self) -> None:
def forward(self) -> None:
self._dispatch("navigate_forward", (self._driver,), "forward", ())

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

Expand Down
3 changes: 2 additions & 1 deletion py/selenium/webdriver/webkitgtk/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# under the License.

import http.client as http_client
from typing import Optional

from selenium.webdriver.common.driver_finder import DriverFinder
from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver
Expand All @@ -30,7 +31,7 @@ class WebDriver(RemoteWebDriver):
def __init__(
self,
options=None,
service: Service = None,
service: Optional[Service] = None,
):
"""Creates a new instance of the WebKitGTK driver.

Expand Down
3 changes: 2 additions & 1 deletion py/selenium/webdriver/wpewebkit/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# under the License.

import http.client as http_client
from typing import Optional

from selenium.webdriver.common.driver_finder import DriverFinder
from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver
Expand All @@ -30,7 +31,7 @@ class WebDriver(RemoteWebDriver):
def __init__(
self,
options=None,
service: Service = None,
service: Optional[Service] = None,
):
"""Creates a new instance of the WPEWebKit driver.

Expand Down
Loading