Skip to content

Commit dbaaa83

Browse files
authored
CI: Run Pyrefly (#884)
1 parent 9ef0eb7 commit dbaaa83

File tree

8 files changed

+33
-20
lines changed

8 files changed

+33
-20
lines changed

.github/workflows/tox.yml

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,12 @@ jobs:
2626
$RUNNER_TOOL_CACHE/Python/*
2727
~\AppData\Local\pip\Cache
2828
key: ${{ runner.os }}-build-${{ matrix.python-version }}
29-
- name: install-tox
30-
run: python -m pip install --upgrade tox virtualenv setuptools pip
31-
- name: run-tox
32-
run: tox -e py
33-
- name: Upload coverage to Codecov
34-
uses: codecov/codecov-action@v3
35-
if: matrix.python-version == '3.8' && matrix.os == 'ubuntu-18.04'
36-
with:
37-
env_vars: OS,PYTHON
38-
name: codecov-umbrella
39-
fail_ci_if_error: true
29+
- name: install-reqs
30+
run: |
31+
python -m pip install --upgrade tox virtualenv setuptools pip
32+
python -m pip install -U -r requirements-dev.txt
33+
python -m pip install -e .
34+
- name: run-tests
35+
run: pytest tests --cov=100
36+
- name: run-pyrefly
37+
run: pyrefly check nbqa

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ repos:
4242
hooks:
4343
- id: mypy
4444
exclude: ^docs/
45-
additional_dependencies: [types-setuptools, types-toml]
45+
additional_dependencies: [types-setuptools, types-toml, tokenize-rt]
4646
- repo: https://github.com/asottile/pyupgrade
4747
rev: v3.19.1
4848
hooks:

nbqa/__main__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,10 @@ def _get_configs(cli_args: CLIArgs, project_root: Path) -> Configs:
460460
if getattr(cli_args, section) is not None:
461461
if section == "addopts":
462462
# addopts are added to / overridden rather than replaced outright
463-
config["addopts"] = (*config["addopts"], *getattr(cli_args, section))
463+
config["addopts"] = ( # type: ignore[missing-attribute,unused-ignore]
464+
*config["addopts"],
465+
*getattr(cli_args, section),
466+
)
464467
else:
465468
# TypedDict key must be a string literal
466469
config[section] = getattr(cli_args, section) # type: ignore
@@ -767,7 +770,7 @@ def _main(cli_args: CLIArgs, configs: Configs) -> int:
767770
for key, i in nb_to_tmp_mapping.items()
768771
if key
769772
not in (
770-
*saved_sources.failed_notebooks,
773+
*saved_sources.failed_notebooks, # type: ignore[not-a-type, unused-ignore]
771774
*saved_sources.non_python_notebooks,
772775
)
773776
],

nbqa/path_utils.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import os
55
import string
66
from pathlib import Path
7-
from typing import Any, Dict, Optional, Tuple
7+
from typing import Any, Dict, Optional, Tuple, cast
88

99

1010
def remove_prefix(string_: str, prefix: str) -> str:
@@ -106,7 +106,10 @@ def read_notebook(notebook: str) -> Tuple[Optional[Dict[str, Any]], Optional[boo
106106
config = None
107107

108108
try:
109-
md_content = jupytext.jupytext.read(notebook, config=config)
109+
# jupytext isn't typed unfortunately
110+
md_content = cast( # type: ignore[missing-attribute,unused-ignore]
111+
Any, jupytext.jupytext.read(notebook, config=config)
112+
)
110113
except: # noqa: E72a # pylint: disable=bare-except
111114
return None, None
112115

nbqa/replace_source.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def _restore_semicolon(
5858
for idx, token in tokenize_rt.reversed_enumerate(tokens):
5959
if not token.src.strip(" \n") or token.name == "COMMENT":
6060
continue
61-
tokens[idx] = token._replace(src=token.src + ";")
61+
tokens[idx] = token._replace(src=token.src + ";") # type: ignore[missing-attribute,unused-ignore]
6262
break
6363
source = tokenize_rt.tokens_to_src(tokens)
6464
return source
@@ -226,7 +226,9 @@ def _write_notebook(
226226

227227
for cell in notebook_json["cells"]:
228228
cell["source"] = "".join(cell["source"])
229-
jupytext.jupytext.write(notebook_json, temp_notebook, config=config)
229+
jupytext.jupytext.write( # type: ignore[missing-attribute,unused-ignore]
230+
notebook_json, temp_notebook, config=config
231+
)
230232

231233

232234
def mutate( # pylint: disable=too-many-locals,too-many-arguments

nbqa/save_code_source.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ def _has_trailing_semicolon(src: str) -> tuple[str, bool]:
328328
if not token.src.strip(" \n") or token.name == "COMMENT":
329329
continue
330330
if token.name == "OP" and token.src == ";":
331-
tokens[idx] = token._replace(src="")
331+
tokens[idx] = token._replace(src="") # type: ignore[missing-attribute,unused-ignore]
332332
trailing_semicolon = True
333333
break
334334
if not trailing_semicolon:

requirements-dev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pre-commit
1212
pre-commit-hooks
1313
pydocstyle
1414
pylint
15+
pyrefly
1516
pytest
1617
pytest-cov
1718
pytest-randomly

tox.ini

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tox]
2-
envlist = py{38,39,310,311}, docs, docs-links
2+
envlist = pyrefly, py{38,39,310,311}, docs, docs-links
33

44
[testenv:docs]
55
deps = -rdocs/requirements-docs.txt
@@ -19,3 +19,9 @@ commands =
1919
coverage run -m pytest {posargs:tests -vv -W error}
2020
coverage xml
2121
coverage report --fail-under 100 --show-missing
22+
23+
[testenv:pyrefly]
24+
deps =
25+
-rrequirements-dev.txt
26+
commands =
27+
pyrefly check nbqa

0 commit comments

Comments
 (0)