Skip to content

Commit 4b69c4b

Browse files
committed
Merge remote-tracking branch 'origin/trunk' into setup
2 parents 045ab3b + 875f0a6 commit 4b69c4b

File tree

31 files changed

+190
-135
lines changed

31 files changed

+190
-135
lines changed

java/src/org/openqa/selenium/internal/Require.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,8 @@ public static int positive(String argName, Integer number, String message) {
129129
throw new IllegalArgumentException(String.format(MUST_BE_SET, argName));
130130
}
131131
if (number <= 0) {
132-
if (message == null) {
133-
throw new IllegalArgumentException(String.format(MUST_BE_POSITIVE, argName));
134-
} else {
135-
throw new IllegalArgumentException(message);
136-
}
132+
throw new IllegalArgumentException(
133+
Objects.requireNonNullElseGet(message, () -> String.format(MUST_BE_POSITIVE, argName)));
137134
}
138135
return number;
139136
}
@@ -143,11 +140,8 @@ public static double positive(String argName, Double number, String message) {
143140
throw new IllegalArgumentException(String.format(MUST_BE_SET, argName));
144141
}
145142
if (number <= 0) {
146-
if (message == null) {
147-
throw new IllegalArgumentException(String.format(MUST_BE_POSITIVE, argName));
148-
} else {
149-
throw new IllegalArgumentException(message);
150-
}
143+
throw new IllegalArgumentException(
144+
Objects.requireNonNullElseGet(message, () -> String.format(MUST_BE_POSITIVE, argName)));
151145
}
152146
return number;
153147
}

py/docs/source/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ If you have `pip <https://pip.pypa.io/>`_ on your system, you can simply install
3535

3636
Alternately, you can download the source distribution from `PyPI <https://pypi.org/project/selenium/#files>`, unarchive it, and run::
3737

38-
python setup.py install
38+
python -m pip install .
3939

4040
Note: You may want to consider using `virtualenv <http://www.virtualenv.org/>`_ to create isolated Python environments.
4141

py/generate.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
from pathlib import Path
3737
import re
3838
from textwrap import dedent, indent as tw_indent
39-
import typing
39+
from typing import Optional , cast, List, Union, Iterator
4040

4141
import inflection # type: ignore
4242

@@ -206,11 +206,11 @@ def from_json(cls, type):
206206
class CdpProperty:
207207
''' A property belonging to a non-primitive CDP type. '''
208208
name: str
209-
description: typing.Optional[str]
210-
type: typing.Optional[str]
211-
ref: typing.Optional[str]
212-
enum: typing.List[str]
213-
items: typing.Optional[CdpItems]
209+
description: Optional[str]
210+
type: Optional[str]
211+
ref: Optional[str]
212+
enum: List[str]
213+
items: Optional[CdpItems]
214214
optional: bool
215215
experimental: bool
216216
deprecated: bool
@@ -236,7 +236,7 @@ def py_annotation(self):
236236
ann = py_ref
237237
else:
238238
ann = CdpPrimitiveType.get_annotation(
239-
typing.cast(str, self.type))
239+
cast(str, self.type))
240240
if self.optional:
241241
ann = f'typing.Optional[{ann}]'
242242
return ann
@@ -316,11 +316,11 @@ def generate_from_json(self, dict_):
316316
class CdpType:
317317
''' A top-level CDP type. '''
318318
id: str
319-
description: typing.Optional[str]
319+
description: Optional[str]
320320
type: str
321-
items: typing.Optional[CdpItems]
322-
enum: typing.List[str]
323-
properties: typing.List[CdpProperty]
321+
items: Optional[CdpItems]
322+
enum: List[str]
323+
properties: List[CdpProperty]
324324

325325
@classmethod
326326
def from_json(cls, type_):
@@ -500,7 +500,7 @@ def generate_code(self):
500500
py_type = f"{ref_to_python(self.ref)}"
501501
else:
502502
py_type = CdpPrimitiveType.get_annotation(
503-
typing.cast(str, self.type))
503+
cast(str, self.type))
504504
if self.optional:
505505
py_type = f'typing.Optional[{py_type}]'
506506
code = f"{self.py_name}: {py_type}"
@@ -585,8 +585,8 @@ class CdpCommand:
585585
description: str
586586
experimental: bool
587587
deprecated: bool
588-
parameters: typing.List[CdpParameter]
589-
returns: typing.List[CdpReturn]
588+
parameters: List[CdpParameter]
589+
returns: List[CdpReturn]
590590
domain: str
591591

592592
@property
@@ -605,8 +605,8 @@ def from_json(cls, command, domain) -> 'CdpCommand':
605605
command.get('description'),
606606
command.get('experimental', False),
607607
command.get('deprecated', False),
608-
[typing.cast(CdpParameter, CdpParameter.from_json(p)) for p in parameters],
609-
[typing.cast(CdpReturn, CdpReturn.from_json(r)) for r in returns],
608+
[cast(CdpParameter, CdpParameter.from_json(p)) for p in parameters],
609+
[cast(CdpReturn, CdpReturn.from_json(r)) for r in returns],
610610
domain,
611611
)
612612

@@ -712,10 +712,10 @@ def get_refs(self):
712712
class CdpEvent:
713713
''' A CDP event object. '''
714714
name: str
715-
description: typing.Optional[str]
715+
description: Optional[str]
716716
deprecated: bool
717717
experimental: bool
718-
parameters: typing.List[CdpParameter]
718+
parameters: List[CdpParameter]
719719
domain: str
720720

721721
@property
@@ -731,7 +731,7 @@ def from_json(cls, json: dict, domain: str):
731731
json.get('description'),
732732
json.get('deprecated', False),
733733
json.get('experimental', False),
734-
[typing.cast(CdpParameter, CdpParameter.from_json(p))
734+
[cast(CdpParameter, CdpParameter.from_json(p))
735735
for p in json.get('parameters', [])],
736736
domain
737737
)
@@ -786,12 +786,12 @@ def get_refs(self):
786786
class CdpDomain:
787787
''' A CDP domain contains metadata, types, commands, and events. '''
788788
domain: str
789-
description: typing.Optional[str]
789+
description: Optional[str]
790790
experimental: bool
791-
dependencies: typing.List[str]
792-
types: typing.List[CdpType]
793-
commands: typing.List[CdpCommand]
794-
events: typing.List[CdpEvent]
791+
dependencies: List[str]
792+
types: List[CdpType]
793+
commands: List[CdpCommand]
794+
events: List[CdpEvent]
795795

796796
@property
797797
def module(self):
@@ -826,8 +826,8 @@ def generate_code(self):
826826
code += import_code
827827
code += '\n\n'
828828
code += '\n'
829-
item_iter_t = typing.Union[CdpEvent, CdpCommand, CdpType]
830-
item_iter: typing.Iterator[item_iter_t] = itertools.chain(
829+
item_iter_t = Union[CdpEvent, CdpCommand, CdpType]
830+
item_iter: Iterator[item_iter_t] = itertools.chain(
831831
iter(self.types),
832832
iter(self.commands),
833833
iter(self.events),

py/selenium/types.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,14 @@
1616
# under the License.
1717
"""Selenium type definitions."""
1818

19-
import typing
19+
from typing import IO
20+
from typing import Any
21+
from typing import Iterable
22+
from typing import Type
23+
from typing import Union
2024

21-
AnyKey = typing.Union[str, int, float]
22-
WaitExcTypes = typing.Iterable[typing.Type[Exception]]
25+
AnyKey = Union[str, int, float]
26+
WaitExcTypes = Iterable[Type[Exception]]
2327

2428
# Service Types
25-
SubprocessStdAlias = typing.Union[int, str, typing.IO[typing.Any]]
29+
SubprocessStdAlias = Union[int, str, IO[Any]]

py/selenium/webdriver/chrome/service.py

Lines changed: 7 additions & 3 deletions
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
@@ -35,9 +39,9 @@ def __init__(
3539
self,
3640
executable_path=None,
3741
port: int = 0,
38-
service_args: typing.Optional[typing.List[str]] = None,
42+
service_args: Optional[List[str]] = None,
3943
log_output: SubprocessStdAlias = None,
40-
env: typing.Optional[typing.Mapping[str, str]] = None,
44+
env: Optional[Mapping[str, str]] = None,
4145
**kwargs,
4246
) -> None:
4347
super().__init__(

py/selenium/webdriver/chromium/service.py

Lines changed: 7 additions & 5 deletions
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
1817
from io import IOBase
18+
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
@@ -36,9 +38,9 @@ def __init__(
3638
self,
3739
executable_path: str = None,
3840
port: int = 0,
39-
service_args: typing.Optional[typing.List[str]] = None,
41+
service_args: Optional[List[str]] = None,
4042
log_output: SubprocessStdAlias = None,
41-
env: typing.Optional[typing.Mapping[str, str]] = None,
43+
env: Optional[Mapping[str, str]] = None,
4244
driver_path_env_key: str = None,
4345
**kwargs,
4446
) -> None:
@@ -47,7 +49,7 @@ def __init__(
4749

4850
if isinstance(log_output, str):
4951
self.service_args.append(f"--log-path={log_output}")
50-
self.log_output: typing.Optional[IOBase] = None
52+
self.log_output: Optional[IOBase] = None
5153
elif isinstance(log_output, IOBase):
5254
self.log_output = log_output
5355
else:
@@ -62,5 +64,5 @@ def __init__(
6264
**kwargs,
6365
)
6466

65-
def command_line_args(self) -> typing.List[str]:
67+
def command_line_args(self) -> List[str]:
6668
return [f"--port={self.port}"] + self.service_args

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +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+
18+
from typing import Any
19+
from typing import Dict
20+
from typing import Optional
1821
from typing import Union
1922

2023
from selenium.common.exceptions import InvalidArgumentException
@@ -41,7 +44,7 @@ def create_pointer_move(
4144
duration=DEFAULT_MOVE_DURATION,
4245
x: float = 0,
4346
y: float = 0,
44-
origin: typing.Optional[WebElement] = None,
47+
origin: Optional[WebElement] = None,
4548
**kwargs,
4649
):
4750
action = {"type": "pointerMove", "duration": duration, "x": x, "y": y, **kwargs}
@@ -67,7 +70,7 @@ def create_pause(self, pause_duration: Union[int, float] = 0) -> None:
6770
def encode(self):
6871
return {"type": self.type, "parameters": {"pointerType": self.kind}, "id": self.name, "actions": self.actions}
6972

70-
def _convert_keys(self, actions: typing.Dict[str, typing.Any]):
73+
def _convert_keys(self, actions: Dict[str, Any]):
7174
out = {}
7275
for k, v in actions.items():
7376
if v is None:

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

Lines changed: 12 additions & 7 deletions
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
@@ -236,7 +241,7 @@ def listen(self, *event_types, buffer_size=10):
236241
return receiver
237242

238243
@asynccontextmanager
239-
async def wait_for(self, event_type: typing.Type[T], buffer_size=10) -> typing.AsyncGenerator[CmEventProxy, None]:
244+
async def wait_for(self, event_type: Type[T], buffer_size=10) -> AsyncGenerator[CmEventProxy, None]:
240245
"""Wait for an event of the given type and return it.
241246
242247
This is an async context manager, so you should open it inside
@@ -406,7 +411,7 @@ async def aclose(self):
406411
await self.ws.aclose()
407412

408413
@asynccontextmanager
409-
async def open_session(self, target_id) -> typing.AsyncIterator[CdpSession]:
414+
async def open_session(self, target_id) -> AsyncIterator[CdpSession]:
410415
"""This context manager opens a session and enables the "simple" style
411416
of calling CDP APIs.
412417
@@ -468,7 +473,7 @@ async def _reader_task(self):
468473

469474

470475
@asynccontextmanager
471-
async def open_cdp(url) -> typing.AsyncIterator[CdpConnection]:
476+
async def open_cdp(url) -> AsyncIterator[CdpConnection]:
472477
"""This async context manager opens a connection to the browser specified
473478
by ``url`` before entering the block, then closes the connection when the
474479
block exits.

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

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

18-
import typing
1918
from dataclasses import dataclass
19+
from typing import List
2020

2121
from .session import session_subscribe
2222
from .session import session_unsubscribe
@@ -76,7 +76,7 @@ class ConsoleLogEntry:
7676
text: str
7777
timestamp: str
7878
method: str
79-
args: typing.List[dict]
79+
args: List[dict]
8080
type_: str
8181

8282
@classmethod

0 commit comments

Comments
 (0)