Skip to content

Commit 0be6efe

Browse files
chore: run pyright on CI as type checker (microsoft#942)
1 parent a0a6536 commit 0be6efe

File tree

8 files changed

+56
-31
lines changed

8 files changed

+56
-31
lines changed

.pre-commit-config.yaml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,24 @@ repos:
1818
hooks:
1919
- id: black
2020
- repo: https://github.com/pre-commit/mirrors-mypy
21-
rev: v0.910
21+
rev: v0.910-1
2222
hooks:
2323
- id: mypy
2424
additional_dependencies: [types-pyOpenSSL==20.0.6]
2525
- repo: https://github.com/pycqa/flake8
26-
rev: 3.9.2
26+
rev: 4.0.1
2727
hooks:
2828
- id: flake8
2929
- repo: https://github.com/pycqa/isort
3030
rev: 5.9.3
3131
hooks:
3232
- id: isort
33+
- repo: local
34+
hooks:
35+
- id: pyright
36+
name: pyright
37+
entry: pyright
38+
language: node
39+
pass_filenames: false
40+
types: [python]
41+
additional_dependencies: ["pyright@1.1.181"]

playwright/_impl/_browser.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import json
1717
from pathlib import Path
1818
from types import SimpleNamespace
19-
from typing import TYPE_CHECKING, Dict, List, Union
19+
from typing import TYPE_CHECKING, Any, Dict, List, Union
2020

2121
from playwright._impl._api_structures import (
2222
Geolocation,
@@ -208,7 +208,8 @@ async def normalize_context_params(is_sync: bool, params: Dict) -> None:
208208
if "extraHTTPHeaders" in params:
209209
params["extraHTTPHeaders"] = serialize_headers(params["extraHTTPHeaders"])
210210
if "recordHarPath" in params:
211-
params["recordHar"] = {"path": str(params["recordHarPath"])}
211+
recordHar: Dict[str, Any] = {"path": str(params["recordHarPath"])}
212+
params["recordHar"] = recordHar
212213
if "recordHarOmitContent" in params:
213214
params["recordHar"]["omitContent"] = params["recordHarOmitContent"]
214215
del params["recordHarOmitContent"]

playwright/_impl/_connection.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,11 @@ def _send_message_to_server(
204204
id = self._last_id
205205
callback = ProtocolCallback(self._loop)
206206
task = asyncio.current_task(self._loop)
207-
callback.stack_trace = getattr(task, "__pw_stack_trace__", None)
208-
if not callback.stack_trace:
209-
callback.stack_trace = traceback.extract_stack()
210-
207+
stack_trace: Optional[traceback.StackSummary] = getattr(
208+
task, "__pw_stack_trace__", None
209+
)
210+
callback.stack_trace = stack_trace or traceback.extract_stack()
211+
self._callbacks[id] = callback
211212
metadata = {"stack": serialize_call_stack(callback.stack_trace)}
212213
api_name = getattr(task, "__pw_api_name__", None)
213214
if api_name:

playwright/_impl/_frame.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ async def query_selector(
265265
async def query_selector_all(self, selector: str) -> List[ElementHandle]:
266266
return list(
267267
map(
268-
cast(ElementHandle, from_channel),
268+
from_channel,
269269
await self._channel.send("querySelectorAll", dict(selector=selector)),
270270
)
271271
)

playwright/_impl/_helper.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ def patch_error_message(message: Optional[str]) -> Optional[str]:
181181
match = re.match(r"(\w+)(: expected .*)", message)
182182
if match:
183183
message = to_snake_case(match.group(1)) + match.group(2)
184+
assert message is not None
184185
message = message.replace(
185186
"Pass { acceptDownloads: true }", "Pass { accept_downloads: True }"
186187
)

playwright/_impl/_selectors.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515
from pathlib import Path
16-
from typing import Dict, Union
16+
from typing import Any, Dict, Union
1717

1818
from playwright._impl._api_types import Error
1919
from playwright._impl._connection import ChannelOwner
@@ -37,7 +37,7 @@ async def register(
3737
raise Error("Either source or path should be specified")
3838
if path:
3939
script = (await async_readfile(path)).decode()
40-
params: Dict = dict(name=name, source=script)
40+
params: Dict[str, Any] = dict(name=name, source=script)
4141
if contentScript:
4242
params["contentScript"] = True
4343
await self._channel.send("register", params)

pyproject.toml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,36 @@
11
[build-system]
22
requires = ["setuptools-scm==6.3.2", "wheel==0.37.0", "auditwheel==5.0.0"]
33
build-backend = "setuptools.build_meta"
4+
5+
[tool.pytest.ini_options]
6+
addopts = "-Wall -rsx -vv -s"
7+
markers = [
8+
"skip_browser",
9+
"only_browser",
10+
"skip_platform",
11+
"only_platform"
12+
]
13+
junit_family = "xunit2"
14+
15+
[tool.mypy]
16+
ignore_missing_imports = true
17+
python_version = "3.7"
18+
warn_unused_ignores = true
19+
warn_redundant_casts = true
20+
warn_unused_configs = true
21+
check_untyped_defs = true
22+
disallow_untyped_defs = true
23+
24+
[[tool.mypy.overrides]]
25+
module = "tests/async.*"
26+
ignore_errors = true
27+
28+
[tool.isort]
29+
profile = "black"
30+
31+
[tool.pyright]
32+
include = ["playwright"]
33+
ignore = ["tests/", "scripts/"]
34+
pythonVersion = "3.7"
35+
reportMissingImports = false
36+
reportTypedDictNotRequiredAccess = false

setup.cfg

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,5 @@
1-
[tool:pytest]
2-
addopts = -Wall -rsx -vv -s
3-
markers =
4-
skip_browser
5-
only_browser
6-
skip_platform
7-
only_platform
8-
junit_family=xunit2
9-
[mypy]
10-
ignore_missing_imports = True
11-
python_version = 3.7
12-
warn_unused_ignores = True
13-
warn_redundant_casts = True
14-
warn_unused_configs = True
15-
check_untyped_defs = True
16-
disallow_untyped_defs = True
17-
[mypy-tests/async.*]
18-
ignore_errors = True
191
[flake8]
202
ignore =
213
E501
224
W503
235
E302
24-
[isort]
25-
profile = black

0 commit comments

Comments
 (0)