Skip to content

Commit d792fcf

Browse files
committed
wholy typing package import replaced with from import
1 parent f3724e6 commit d792fcf

21 files changed

+115
-79
lines changed

py/selenium/webdriver/chrome/remote_connection.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# KIND, either express or implied. See the License for the
1515
# specific language governing permissions and limitations
1616
# under the License.
17-
import typing
17+
from typing import Optional
1818

1919
from selenium.webdriver import DesiredCapabilities
2020
from selenium.webdriver.chromium.remote_connection import ChromiumRemoteConnection
@@ -27,7 +27,7 @@ def __init__(
2727
self,
2828
remote_server_addr: str,
2929
keep_alive: bool = True,
30-
ignore_proxy: typing.Optional[bool] = False,
30+
ignore_proxy: Optional[bool] = False,
3131
) -> None:
3232
super().__init__(
3333
remote_server_addr=remote_server_addr,

py/selenium/webdriver/chrome/service.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
# KIND, either express or implied. See the License for the
1515
# specific language governing permissions and limitations
1616
# under the License.
17-
import typing
17+
from typing import List
18+
from typing import Mapping
19+
from typing import Optional
1820

1921
from selenium.types import SubprocessStdAlias
2022
from selenium.webdriver.chromium import service
@@ -35,9 +37,9 @@ def __init__(
3537
self,
3638
executable_path=None,
3739
port: int = 0,
38-
service_args: typing.Optional[typing.List[str]] = None,
40+
service_args: Optional[List[str]] = None,
3941
log_output: SubprocessStdAlias = None,
40-
env: typing.Optional[typing.Mapping[str, str]] = None,
42+
env: Optional[Mapping[str, str]] = None,
4143
**kwargs,
4244
) -> None:
4345
super().__init__(

py/selenium/webdriver/chromium/service.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
# KIND, either express or implied. See the License for the
1515
# specific language governing permissions and limitations
1616
# under the License.
17-
import typing
17+
from typing import List
18+
from typing import Mapping
19+
from typing import Optional
1820

1921
from selenium.types import SubprocessStdAlias
2022
from selenium.webdriver.common import service
@@ -35,9 +37,9 @@ def __init__(
3537
self,
3638
executable_path: str = None,
3739
port: int = 0,
38-
service_args: typing.Optional[typing.List[str]] = None,
40+
service_args: Optional[List[str]] = None,
3941
log_output: SubprocessStdAlias = None,
40-
env: typing.Optional[typing.Mapping[str, str]] = None,
42+
env: Optional[Mapping[str, str]] = None,
4143
**kwargs,
4244
) -> None:
4345
self.service_args = service_args or []
@@ -56,5 +58,5 @@ def __init__(
5658
**kwargs,
5759
)
5860

59-
def command_line_args(self) -> typing.List[str]:
61+
def command_line_args(self) -> List[str]:
6062
return [f"--port={self.port}"] + self.service_args

py/selenium/webdriver/common/actions/pointer_input.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
# KIND, either express or implied. See the License for the
1515
# specific language governing permissions and limitations
1616
# under the License.
17-
import typing
17+
from typing import Any
18+
from typing import Dict
19+
from typing import Optional
1820

1921
from selenium.common.exceptions import InvalidArgumentException
2022
from selenium.webdriver.remote.webelement import WebElement
@@ -40,7 +42,7 @@ def create_pointer_move(
4042
duration=DEFAULT_MOVE_DURATION,
4143
x: float = 0,
4244
y: float = 0,
43-
origin: typing.Optional[WebElement] = None,
45+
origin: Optional[WebElement] = None,
4446
**kwargs,
4547
):
4648
action = {"type": "pointerMove", "duration": duration, "x": x, "y": y, **kwargs}
@@ -66,7 +68,7 @@ def create_pause(self, pause_duration: float) -> None:
6668
def encode(self):
6769
return {"type": self.type, "parameters": {"pointerType": self.kind}, "id": self.name, "actions": self.actions}
6870

69-
def _convert_keys(self, actions: typing.Dict[str, typing.Any]):
71+
def _convert_keys(self, actions: Dict[str, Any]):
7072
out = {}
7173
for k, v in actions.items():
7274
if v is None:

py/selenium/webdriver/common/bidi/cdp.py

+12-7
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,23 @@
3030
import json
3131
import logging
3232
import pathlib
33-
import typing
3433
from collections import defaultdict
3534
from contextlib import asynccontextmanager
3635
from contextlib import contextmanager
3736
from dataclasses import dataclass
37+
from typing import Any
38+
from typing import AsyncGenerator
39+
from typing import AsyncIterator
40+
from typing import Generator
41+
from typing import Type
42+
from typing import TypeVar
3843

3944
import trio
4045
from trio_websocket import ConnectionClosed as WsConnectionClosed
4146
from trio_websocket import connect_websocket_url
4247

4348
logger = logging.getLogger("trio_cdp")
44-
T = typing.TypeVar("T")
49+
T = TypeVar("T")
4550
MAX_WS_MESSAGE_SIZE = 2**24
4651

4752
devtools = None
@@ -184,7 +189,7 @@ class CmEventProxy:
184189
value set that contains the returned event.
185190
"""
186191

187-
value: typing.Any = None
192+
value: Any = None
188193

189194

190195
class CdpBase:
@@ -197,7 +202,7 @@ def __init__(self, ws, session_id, target_id):
197202
self.inflight_cmd = {}
198203
self.inflight_result = {}
199204

200-
async def execute(self, cmd: typing.Generator[dict, T, typing.Any]) -> T:
205+
async def execute(self, cmd: Generator[dict, T, Any]) -> T:
201206
"""Execute a command on the server and wait for the result.
202207
203208
:param cmd: any CDP command
@@ -230,7 +235,7 @@ def listen(self, *event_types, buffer_size=10):
230235
return receiver
231236

232237
@asynccontextmanager
233-
async def wait_for(self, event_type: typing.Type[T], buffer_size=10) -> typing.AsyncGenerator[CmEventProxy, None]:
238+
async def wait_for(self, event_type: Type[T], buffer_size=10) -> AsyncGenerator[CmEventProxy, None]:
234239
"""Wait for an event of the given type and return it.
235240
236241
This is an async context manager, so you should open it inside
@@ -398,7 +403,7 @@ async def aclose(self):
398403
await self.ws.aclose()
399404

400405
@asynccontextmanager
401-
async def open_session(self, target_id) -> typing.AsyncIterator[CdpSession]:
406+
async def open_session(self, target_id) -> AsyncIterator[CdpSession]:
402407
"""This context manager opens a session and enables the "simple" style
403408
of calling CDP APIs.
404409
@@ -460,7 +465,7 @@ async def _reader_task(self):
460465

461466

462467
@asynccontextmanager
463-
async def open_cdp(url) -> typing.AsyncIterator[CdpConnection]:
468+
async def open_cdp(url) -> AsyncIterator[CdpConnection]:
464469
"""This async context manager opens a connection to the browser specified
465470
by ``url`` before entering the block, then closes the connection when the
466471
block exits.

py/selenium/webdriver/common/bidi/script.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
import typing
18+
1919
from dataclasses import dataclass
20+
from typing import List
2021

2122
from .session import session_subscribe
2223
from .session import session_unsubscribe
@@ -77,7 +78,7 @@ class ConsoleLogEntry:
7778
text: str
7879
timestamp: str
7980
method: str
80-
args: typing.List[dict]
81+
args: List[dict]
8182
type_: str
8283

8384
@classmethod

py/selenium/webdriver/common/options.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414
# KIND, either express or implied. See the License for the
1515
# specific language governing permissions and limitations
1616
# under the License.
17-
import typing
17+
1818
from abc import ABCMeta
1919
from abc import abstractmethod
2020
from enum import Enum
21+
from typing import Optional
2122

2223
from selenium.common.exceptions import InvalidArgumentException
2324
from selenium.webdriver.common.proxy import Proxy
@@ -456,9 +457,9 @@ def set_capability(self, name, value) -> None:
456457

457458
def enable_mobile(
458459
self,
459-
android_package: typing.Optional[str] = None,
460-
android_activity: typing.Optional[str] = None,
461-
device_serial: typing.Optional[str] = None,
460+
android_package: Optional[str] = None,
461+
android_activity: Optional[str] = None,
462+
device_serial: Optional[str] = None,
462463
) -> None:
463464
"""Enables mobile browser use for browsers that support it.
464465

py/selenium/webdriver/common/service.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@
1818
import logging
1919
import os
2020
import subprocess
21-
import typing
2221
from abc import ABC
2322
from abc import abstractmethod
2423
from io import IOBase
2524
from platform import system
2625
from subprocess import PIPE
2726
from time import sleep
27+
from typing import Any
28+
from typing import List
29+
from typing import Mapping
30+
from typing import Optional
2831
from urllib import request
2932
from urllib.error import URLError
3033

@@ -51,7 +54,7 @@ def __init__(
5154
executable_path: str = None,
5255
port: int = 0,
5356
log_output: SubprocessStdAlias = None,
54-
env: typing.Optional[typing.Mapping[typing.Any, typing.Any]] = None,
57+
env: Optional[Mapping[Any, Any]] = None,
5558
**kwargs,
5659
) -> None:
5760
if isinstance(log_output, str):
@@ -76,7 +79,7 @@ def service_url(self) -> str:
7679
return f"http://{utils.join_host_port('localhost', self.port)}"
7780

7881
@abstractmethod
79-
def command_line_args(self) -> typing.List[str]:
82+
def command_line_args(self) -> List[str]:
8083
"""A List of program arguments (excluding the executable)."""
8184
raise NotImplementedError("This method needs to be implemented in a sub class")
8285

py/selenium/webdriver/common/virtual_authenticator.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@
1616
# under the License.
1717

1818
import functools
19-
import typing
2019
from base64 import urlsafe_b64decode
2120
from base64 import urlsafe_b64encode
2221
from enum import Enum
22+
from typing import Any
23+
from typing import Dict
24+
from typing import Optional
25+
from typing import Union
2326

2427

2528
class Protocol(str, Enum):
@@ -65,7 +68,7 @@ def __init__(
6568
self.is_user_consenting: bool = is_user_consenting
6669
self.is_user_verified: bool = is_user_verified
6770

68-
def to_dict(self) -> typing.Dict[str, typing.Union[str, bool]]:
71+
def to_dict(self) -> Dict[str, Union[str, bool]]:
6972
return {
7073
"protocol": self.protocol,
7174
"transport": self.transport,
@@ -82,7 +85,7 @@ def __init__(
8285
credential_id: bytes,
8386
is_resident_credential: bool,
8487
rp_id: str,
85-
user_handle: typing.Optional[bytes],
88+
user_handle: Optional[bytes],
8689
private_key: bytes,
8790
sign_count: int,
8891
):
@@ -117,7 +120,7 @@ def rp_id(self) -> str:
117120
return self._rp_id
118121

119122
@property
120-
def user_handle(self) -> typing.Optional[str]:
123+
def user_handle(self) -> Optional[str]:
121124
if self._user_handle:
122125
return urlsafe_b64encode(self._user_handle).decode()
123126
return None
@@ -147,7 +150,7 @@ def create_non_resident_credential(cls, id: bytes, rp_id: str, private_key: byte
147150

148151
@classmethod
149152
def create_resident_credential(
150-
cls, id: bytes, rp_id: str, user_handle: typing.Optional[bytes], private_key: bytes, sign_count: int
153+
cls, id: bytes, rp_id: str, user_handle: Optional[bytes], private_key: bytes, sign_count: int
151154
) -> "Credential":
152155
"""Creates a resident (i.e. stateful) credential.
153156
@@ -163,7 +166,7 @@ def create_resident_credential(
163166
"""
164167
return cls(id, True, rp_id, user_handle, private_key, sign_count)
165168

166-
def to_dict(self) -> typing.Dict[str, typing.Any]:
169+
def to_dict(self) -> Dict[str, Any]:
167170
credential_data = {
168171
"credentialId": self.id,
169172
"isResidentCredential": self._is_resident_credential,
@@ -178,7 +181,7 @@ def to_dict(self) -> typing.Dict[str, typing.Any]:
178181
return credential_data
179182

180183
@classmethod
181-
def from_dict(cls, data: typing.Dict[str, typing.Any]) -> "Credential":
184+
def from_dict(cls, data: Dict[str, Any]) -> "Credential":
182185
_id = urlsafe_b64decode(f"{data['credentialId']}==")
183186
is_resident_credential = bool(data["isResidentCredential"])
184187
rp_id = data.get("rpId", None)

py/selenium/webdriver/edge/remote_connection.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# KIND, either express or implied. See the License for the
1515
# specific language governing permissions and limitations
1616
# under the License.
17-
import typing
17+
from typing import Optional
1818

1919
from selenium.webdriver import DesiredCapabilities
2020
from selenium.webdriver.chromium.remote_connection import ChromiumRemoteConnection
@@ -27,7 +27,7 @@ def __init__(
2727
self,
2828
remote_server_addr: str,
2929
keep_alive: bool = True,
30-
ignore_proxy: typing.Optional[bool] = False,
30+
ignore_proxy: Optional[bool] = False,
3131
) -> None:
3232
super().__init__(
3333
remote_server_addr=remote_server_addr,

py/selenium/webdriver/edge/service.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414
# KIND, either express or implied. See the License for the
1515
# specific language governing permissions and limitations
1616
# under the License.
17-
import typing
17+
18+
19+
from typing import List
20+
from typing import Mapping
21+
from typing import Optional
1822

1923
from selenium.types import SubprocessStdAlias
2024
from selenium.webdriver.chromium import service
@@ -38,8 +42,8 @@ def __init__(
3842
executable_path: str = None,
3943
port: int = 0,
4044
log_output: SubprocessStdAlias = None,
41-
service_args: typing.Optional[typing.List[str]] = None,
42-
env: typing.Optional[typing.Mapping[str, str]] = None,
45+
service_args: Optional[List[str]] = None,
46+
env: Optional[Mapping[str, str]] = None,
4347
**kwargs,
4448
) -> None:
4549
self.service_args = service_args or []

py/selenium/webdriver/firefox/service.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414
# KIND, either express or implied. See the License for the
1515
# specific language governing permissions and limitations
1616
# under the License.
17-
import typing
17+
1818
from typing import List
19+
from typing import Mapping
20+
from typing import Optional
1921

2022
from selenium.types import SubprocessStdAlias
2123
from selenium.webdriver.common import service
@@ -37,9 +39,9 @@ def __init__(
3739
self,
3840
executable_path: str = None,
3941
port: int = 0,
40-
service_args: typing.Optional[typing.List[str]] = None,
42+
service_args: Optional[List[str]] = None,
4143
log_output: SubprocessStdAlias = None,
42-
env: typing.Optional[typing.Mapping[str, str]] = None,
44+
env: Optional[Mapping[str, str]] = None,
4345
**kwargs,
4446
) -> None:
4547
self.service_args = service_args or []

0 commit comments

Comments
 (0)