Skip to content

Commit 5f26616

Browse files
authored
chore: update linters (pyright/mypy/pre-commit) (#2588)
1 parent d9cdfbb commit 5f26616

23 files changed

+171
-81
lines changed

.pre-commit-config.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# See https://pre-commit.com/hooks.html for more hooks
33
repos:
44
- repo: https://github.com/pre-commit/pre-commit-hooks
5-
rev: v4.5.0
5+
rev: v5.0.0
66
hooks:
77
- id: trailing-whitespace
88
- id: end-of-file-fixer
@@ -15,16 +15,16 @@ repos:
1515
- id: check-executables-have-shebangs
1616
- id: check-merge-conflict
1717
- repo: https://github.com/psf/black
18-
rev: 23.9.1
18+
rev: 24.8.0
1919
hooks:
2020
- id: black
2121
- repo: https://github.com/pre-commit/mirrors-mypy
22-
rev: v1.8.0
22+
rev: v1.11.2
2323
hooks:
2424
- id: mypy
25-
additional_dependencies: [types-pyOpenSSL==23.2.0.2, types-requests==2.31.0.10]
25+
additional_dependencies: [types-pyOpenSSL==24.1.0.20240722, types-requests==2.32.0.20240914]
2626
- repo: https://github.com/pycqa/flake8
27-
rev: 6.1.0
27+
rev: 7.1.1
2828
hooks:
2929
- id: flake8
3030
- repo: https://github.com/pycqa/isort
@@ -39,7 +39,7 @@ repos:
3939
language: node
4040
pass_filenames: false
4141
types: [python]
42-
additional_dependencies: ["pyright@1.1.278"]
42+
additional_dependencies: ["pyright@1.1.384"]
4343
- repo: local
4444
hooks:
4545
- id: check-license-header

local-requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ mypy==1.11.2
77
objgraph==3.6.1
88
Pillow==10.4.0
99
pixelmatch==0.3.0
10-
pre-commit==3.4.0
10+
pre-commit==3.5.0
1111
pyOpenSSL==24.2.1
1212
pytest==8.3.3
1313
pytest-asyncio==0.21.2

playwright/_impl/_assertions.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -512,9 +512,11 @@ async def to_be_attached(
512512
) -> None:
513513
__tracebackhide__ = True
514514
await self._expect_impl(
515-
"to.be.attached"
516-
if (attached is None or attached is True)
517-
else "to.be.detached",
515+
(
516+
"to.be.attached"
517+
if (attached is None or attached is True)
518+
else "to.be.detached"
519+
),
518520
FrameExpectOptions(timeout=timeout),
519521
None,
520522
"Locator expected to be attached",
@@ -527,9 +529,11 @@ async def to_be_checked(
527529
) -> None:
528530
__tracebackhide__ = True
529531
await self._expect_impl(
530-
"to.be.checked"
531-
if checked is None or checked is True
532-
else "to.be.unchecked",
532+
(
533+
"to.be.checked"
534+
if checked is None or checked is True
535+
else "to.be.unchecked"
536+
),
533537
FrameExpectOptions(timeout=timeout),
534538
None,
535539
"Locator expected to be checked",

playwright/_impl/_async_base.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import asyncio
1616
from contextlib import AbstractAsyncContextManager
1717
from types import TracebackType
18-
from typing import Any, Callable, Generic, Optional, Type, TypeVar
18+
from typing import Any, Callable, Generic, Optional, Type, TypeVar, Union
1919

2020
from playwright._impl._impl_to_api_mapping import ImplToApiMapping, ImplWrapper
2121

@@ -68,7 +68,9 @@ def __init__(self, impl_obj: Any) -> None:
6868
def __str__(self) -> str:
6969
return self._impl_obj.__str__()
7070

71-
def _wrap_handler(self, handler: Any) -> Callable[..., None]:
71+
def _wrap_handler(
72+
self, handler: Union[Callable[..., Any], Any]
73+
) -> Callable[..., None]:
7274
if callable(handler):
7375
return mapping.wrap_handler(handler)
7476
return handler
@@ -100,5 +102,4 @@ async def __aexit__(
100102
) -> None:
101103
await self.close()
102104

103-
async def close(self) -> None:
104-
...
105+
async def close(self) -> None: ...

playwright/_impl/_browser_context.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -316,21 +316,21 @@ async def clear_cookies(
316316
{
317317
"name": name if isinstance(name, str) else None,
318318
"nameRegexSource": name.pattern if isinstance(name, Pattern) else None,
319-
"nameRegexFlags": escape_regex_flags(name)
320-
if isinstance(name, Pattern)
321-
else None,
319+
"nameRegexFlags": (
320+
escape_regex_flags(name) if isinstance(name, Pattern) else None
321+
),
322322
"domain": domain if isinstance(domain, str) else None,
323-
"domainRegexSource": domain.pattern
324-
if isinstance(domain, Pattern)
325-
else None,
326-
"domainRegexFlags": escape_regex_flags(domain)
327-
if isinstance(domain, Pattern)
328-
else None,
323+
"domainRegexSource": (
324+
domain.pattern if isinstance(domain, Pattern) else None
325+
),
326+
"domainRegexFlags": (
327+
escape_regex_flags(domain) if isinstance(domain, Pattern) else None
328+
),
329329
"path": path if isinstance(path, str) else None,
330330
"pathRegexSource": path.pattern if isinstance(path, Pattern) else None,
331-
"pathRegexFlags": escape_regex_flags(path)
332-
if isinstance(path, Pattern)
333-
else None,
331+
"pathRegexFlags": (
332+
escape_regex_flags(path) if isinstance(path, Pattern) else None
333+
),
334334
},
335335
)
336336

playwright/_impl/_connection.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,9 @@ def cb(task: asyncio.Task) -> None:
197197
if current_task:
198198
current_task.add_done_callback(cb)
199199
self.future.add_done_callback(
200-
lambda _: current_task.remove_done_callback(cb)
201-
if current_task
202-
else None
200+
lambda _: (
201+
current_task.remove_done_callback(cb) if current_task else None
202+
)
203203
)
204204

205205

@@ -243,9 +243,9 @@ def __init__(
243243
self._error: Optional[BaseException] = None
244244
self.is_remote = False
245245
self._init_task: Optional[asyncio.Task] = None
246-
self._api_zone: contextvars.ContextVar[
247-
Optional[ParsedStackTrace]
248-
] = contextvars.ContextVar("ApiZone", default=None)
246+
self._api_zone: contextvars.ContextVar[Optional[ParsedStackTrace]] = (
247+
contextvars.ContextVar("ApiZone", default=None)
248+
)
249249
self._local_utils: Optional["LocalUtils"] = local_utils
250250
self._tracing_count = 0
251251
self._closed_error: Optional[Exception] = None

playwright/_impl/_impl_to_api_mapping.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def to_impl(
117117
except RecursionError:
118118
raise Error("Maximum argument depth exceeded")
119119

120-
def wrap_handler(self, handler: Callable[..., None]) -> Callable[..., None]:
120+
def wrap_handler(self, handler: Callable[..., Any]) -> Callable[..., None]:
121121
def wrapper_func(*args: Any) -> Any:
122122
arg_count = len(inspect.signature(handler).parameters)
123123
return handler(

playwright/_impl/_js_handle.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,17 @@ def serialize_value(
145145
return {
146146
"e": {
147147
"m": str(value),
148-
"n": (value.name or "")
149-
if isinstance(value, Error)
150-
else value.__class__.__name__,
151-
"s": (value.stack or "")
152-
if isinstance(value, Error)
153-
else "".join(
154-
traceback.format_exception(type(value), value=value, tb=None)
148+
"n": (
149+
(value.name or "")
150+
if isinstance(value, Error)
151+
else value.__class__.__name__
152+
),
153+
"s": (
154+
(value.stack or "")
155+
if isinstance(value, Error)
156+
else "".join(
157+
traceback.format_exception(type(value), value=value, tb=None)
158+
)
155159
),
156160
}
157161
}

playwright/_impl/_json_pipe.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ def __init__(
3333
Transport.__init__(self, loop)
3434
self._stop_requested = False
3535
self._pipe_channel = pipe_channel
36-
self._loop: asyncio.AbstractEventLoop
3736

3837
def request_stop(self) -> None:
3938
self._stop_requested = True

playwright/_impl/_sync_base.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,9 @@ def _sync(
114114
asyncio._set_running_loop(self._loop)
115115
return task.result()
116116

117-
def _wrap_handler(self, handler: Any) -> Callable[..., None]:
117+
def _wrap_handler(
118+
self, handler: Union[Callable[..., Any], Any]
119+
) -> Callable[..., None]:
118120
if callable(handler):
119121
return mapping.wrap_handler(handler)
120122
return handler
@@ -146,5 +148,4 @@ def __exit__(
146148
) -> None:
147149
self.close()
148150

149-
def close(self) -> None:
150-
...
151+
def close(self) -> None: ...

0 commit comments

Comments
 (0)