Skip to content

Commit 953a945

Browse files
authored
Merge pull request #202 from jakkdl/update_ci
Update ci
2 parents a652441 + 6f0f574 commit 953a945

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+303
-306
lines changed

.github/workflows/ci.yml

+20-20
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ jobs:
1111
check:
1212
runs-on: ubuntu-latest
1313
steps:
14-
- uses: actions/checkout@v3
15-
- name: Set up Python 3.11
16-
uses: actions/setup-python@v3
14+
- uses: actions/checkout@v4
15+
- name: Set up Python 3.12
16+
uses: actions/setup-python@v5
1717
with:
18-
python-version: '3.11'
18+
python-version: '3.12'
1919
- name: Install dependencies
2020
run: |
2121
python -m pip install --upgrade pip setuptools pre-commit
@@ -27,46 +27,46 @@ jobs:
2727
runs-on: ubuntu-latest
2828
strategy:
2929
matrix:
30-
python-version: ['3.9', '3.10', '3.11']
30+
python-version: ['3.9', '3.10', '3.11', '3.12', 3.13-dev]
3131
fail-fast: false
3232
steps:
33-
- uses: actions/checkout@v3
33+
- uses: actions/checkout@v4
3434
- name: Set up Python ${{ matrix.python-version }}
35-
uses: actions/setup-python@v3
35+
uses: actions/setup-python@v5
3636
with:
3737
python-version: ${{ matrix.python-version }}
3838
- name: Install dependencies
39-
run: |
40-
python -m pip install --upgrade pip setuptools tox
41-
python -m tox --notest --recreate -e flake8_5,flake8_6
42-
- name: Run tests
43-
run: python -m tox -e flake8_5,flake8_6
39+
run: python -m pip install --upgrade pip setuptools tox
40+
- name: Run tests with flake8_6
41+
run: python -m tox -e flake8_6
42+
- name: Run tests with flake8_7+
43+
run: python -m tox -e flake8_7
4444

4545
slow_tests:
4646
runs-on: ubuntu-latest
4747
strategy:
4848
fail-fast: false
4949
steps:
50-
- uses: actions/checkout@v3
51-
- name: Set up Python 3.11
52-
uses: actions/setup-python@v3
50+
- uses: actions/checkout@v4
51+
- name: Set up Python 3.12
52+
uses: actions/setup-python@v5
5353
with:
54-
python-version: 3.11
54+
python-version: 3.12
5555
- name: Install dependencies
5656
run: |
5757
python -m pip install --upgrade pip setuptools tox
58-
python -m tox --notest --recreate -e flake8_6
58+
python -m tox --notest --recreate -e flake8_7
5959
- name: Run tests
60-
run: python -m tox -e flake8_6 -- --onlyfuzz --no-cov -n auto
60+
run: python -m tox -e flake8_7 -- --onlyfuzz --no-cov -n auto
6161

6262
release:
6363
runs-on: ubuntu-latest
6464
needs: [check, test]
6565
if: github.repository == 'Zac-HD/flake8-trio' && github.ref == 'refs/heads/main'
6666
steps:
67-
- uses: actions/checkout@v3
67+
- uses: actions/checkout@v4
6868
- name: Set up Python 3
69-
uses: actions/setup-python@v3
69+
uses: actions/setup-python@v5
7070
- name: Install tools
7171
run: python -m pip install --upgrade build pip setuptools wheel twine gitpython
7272
- name: Upload new release

.pre-commit-config.yaml

+13-35
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,42 @@
11
---
22
default_language_version:
3-
python: python3.11
3+
python: python3.12
44
# pyright requires internet connection to run, which the pre-commit ci app doesn't have.
55
# Not used in this repo.
66
ci:
77
skip: [pyright]
88

99
repos:
1010
- repo: https://github.com/psf/black
11-
rev: 23.1.0
11+
rev: 24.2.0
1212
hooks:
1313
- id: black
1414
args: [--preview]
1515

1616
- repo: https://github.com/PyCQA/autoflake
17-
rev: v2.0.2
17+
rev: v2.2.1
1818
hooks:
1919
- id: autoflake
2020

2121
- repo: https://github.com/asottile/pyupgrade
22-
rev: v3.3.1
22+
rev: v3.15.0
2323
hooks:
2424
- id: pyupgrade
2525
args: [--py39-plus]
26+
exclude: tests/eval_files/trio103.py
2627

2728
- repo: https://github.com/pycqa/isort
28-
rev: 5.12.0
29+
rev: 5.13.2
2930
hooks:
3031
- id: isort
3132

3233
- repo: https://github.com/pre-commit/mirrors-mypy
33-
rev: v1.1.1
34+
rev: v1.8.0
3435
hooks:
3536
- id: mypy
3637

3738
- repo: https://github.com/RobertCraigie/pyright-python
38-
rev: v1.1.299
39+
rev: v1.1.350
3940
hooks:
4041
- id: pyright
4142
# ignore warnings about new version being available, no other warnings
@@ -53,14 +54,14 @@ repos:
5354
- trio
5455

5556
- repo: https://github.com/codespell-project/codespell
56-
rev: v2.2.4
57+
rev: v2.2.6
5758
hooks:
5859
- id: codespell
5960
additional_dependencies:
6061
- tomli
6162

6263
- repo: https://github.com/pre-commit/pre-commit-hooks
63-
rev: v4.4.0
64+
rev: v4.5.0
6465
hooks:
6566
- id: check-merge-conflict
6667
- id: check-toml
@@ -74,40 +75,17 @@ repos:
7475
args: ['--markdown-linebreak-ext=md,markdown']
7576

7677
- repo: https://github.com/charliermarsh/ruff-pre-commit
77-
rev: v0.0.269
78+
rev: v0.2.1
7879
hooks:
7980
- id: ruff
8081

81-
- repo: https://github.com/PyCQA/flake8
82-
rev: 6.0.0
83-
hooks:
84-
- id: flake8
85-
# this doesn't seem to work, pyi files don't get checked with --all-files
86-
types_or: [python, pyi]
87-
language_version: python3
88-
additional_dependencies:
89-
- flake8-2020
90-
- flake8-bugbear
91-
- flake8-builtins
92-
- flake8-comprehensions
93-
- flake8-datetimez
94-
- flake8-docstrings
95-
- flake8-mutable # not official supported by ruff
96-
- flake8-pie
97-
- flake8-pyi
98-
- flake8-pytest-style
99-
- flake8-return
100-
- flake8-simplify
101-
- flake8-type-checking
102-
# all other are
103-
10482
- repo: https://github.com/jumanjihouse/pre-commit-hook-yamlfmt
105-
rev: 0.2.2
83+
rev: 0.2.3
10684
hooks:
10785
- id: yamlfmt
10886

10987
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
110-
rev: v2.8.0
88+
rev: v2.12.0
11189
hooks:
11290
- id: pretty-format-toml
11391
args: [--autofix]

flake8_trio/__main__.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Entry file when executed with `python -m`."""
2+
23
import sys
34

45
from . import main

flake8_trio/base.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from __future__ import annotations
44

55
from dataclasses import dataclass
6-
from typing import TYPE_CHECKING, Any, NamedTuple
6+
from typing import TYPE_CHECKING, NamedTuple
77

88
if TYPE_CHECKING:
99
from collections.abc import Collection
@@ -29,10 +29,12 @@ class Statement(NamedTuple):
2929
lineno: int
3030
col_offset: int = -1
3131

32-
def __eq__(self, other: Any) -> bool:
32+
# pyright is unhappy about defining __eq__ but not __hash__ .. which it should
33+
# but it works :tm: and needs changing in a couple places to avoid it.
34+
def __eq__(self, other: object) -> bool:
3335
return (
3436
isinstance(other, Statement)
35-
and self[:2] == other[:2] # type: ignore
37+
and self[:2] == other[:2]
3638
and (
3739
self.col_offset == other.col_offset
3840
or -1 in (self.col_offset, other.col_offset)
@@ -68,11 +70,11 @@ def cmp(self):
6870
return self.line, self.code, self.args, self.col
6971

7072
# for sorting in tests
71-
def __lt__(self, other: Any) -> bool:
73+
def __lt__(self, other: Error) -> bool:
7274
assert isinstance(other, Error)
7375
return self.cmp() < other.cmp()
7476

75-
def __eq__(self, other: Any) -> bool:
77+
def __eq__(self, other: object) -> bool:
7678
return isinstance(other, Error) and self.cmp() == other.cmp()
7779

7880
def __repr__(self) -> str: # pragma: no cover

flake8_trio/visitors/flake8triovisitor.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import ast
66
from abc import ABC
7-
from typing import TYPE_CHECKING, Any, Union
7+
from typing import TYPE_CHECKING, Any, ClassVar, Union
88

99
import libcst as cst
1010
from libcst.metadata import PositionProvider
@@ -23,7 +23,7 @@
2323

2424
class Flake8TrioVisitor(ast.NodeVisitor, ABC):
2525
# abstract attribute by not providing a value
26-
error_codes: dict[str, str] # pyright: ignore[reportUninitializedInstanceVariable]
26+
error_codes: ClassVar[dict[str, str]]
2727

2828
def __init__(self, shared_state: SharedState):
2929
super().__init__()
@@ -158,7 +158,7 @@ def add_library(self, name: str) -> None:
158158

159159
class Flake8TrioVisitor_cst(cst.CSTTransformer, ABC):
160160
# abstract attribute by not providing a value
161-
error_codes: dict[str, str] # pyright: ignore[reportUninitializedInstanceVariable]
161+
error_codes: dict[str, str]
162162
METADATA_DEPENDENCIES = (PositionProvider,)
163163

164164
def __init__(self, shared_state: SharedState):

flake8_trio/visitors/helpers.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import ast
99
from fnmatch import fnmatch
10-
from typing import TYPE_CHECKING, NamedTuple, TypeVar
10+
from typing import TYPE_CHECKING, NamedTuple, TypeVar, Union
1111

1212
import libcst as cst
1313
import libcst.matchers as m
@@ -29,7 +29,9 @@
2929

3030
T = TypeVar("T", bound=Flake8TrioVisitor)
3131
T_CST = TypeVar("T_CST", bound=Flake8TrioVisitor_cst)
32-
T_EITHER = TypeVar("T_EITHER", bound=Flake8TrioVisitor | Flake8TrioVisitor_cst)
32+
T_EITHER = TypeVar(
33+
"T_EITHER", bound=Union[Flake8TrioVisitor, Flake8TrioVisitor_cst]
34+
)
3335

3436

3537
def error_class(error_class: type[T]) -> type[T]:

flake8_trio/visitors/visitor100.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
the timeout can only be triggered by a checkpoint.
66
Checkpoints on Await, Async For and Async With
77
"""
8+
89
from __future__ import annotations
910

1011
from typing import Any
1112

12-
import libcst as cst # noqa: TCH002
13+
import libcst as cst
1314
import libcst.matchers as m
1415

1516
from .flake8triovisitor import Flake8TrioVisitor_cst

flake8_trio/visitors/visitor101.py

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
`yield` inside a nursery or cancel scope is only safe when implementing a context manager
44
- otherwise, it breaks exception handling.
55
"""
6+
67
from __future__ import annotations
78

89
from typing import TYPE_CHECKING, Any

flake8_trio/visitors/visitor103_104.py

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
an improper raise, or other flow control, is encountered.
77
"""
88

9-
109
from __future__ import annotations
1110

1211
import ast

flake8_trio/visitors/visitor118.py

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
that breaks linter checks and multi-backend programs.
55
"""
66

7-
87
from __future__ import annotations
98

109
import ast

flake8_trio/visitors/visitor91x.py

+14-7
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,16 @@
3535
def func_empty_body(node: cst.FunctionDef) -> bool:
3636
"""Check if function body consist of `pass`, `...`, and/or (doc)string literals."""
3737
empty_statement = m.Pass() | m.Expr(m.Ellipsis() | m.SimpleString())
38+
3839
return m.matches(
3940
node.body,
40-
m.IndentedBlock(
41-
[m.ZeroOrMore(m.SimpleStatementLine([m.ZeroOrMore(empty_statement)]))]
41+
m.OneOf(
42+
# newline + indented statements
43+
m.IndentedBlock(
44+
[m.ZeroOrMore(m.SimpleStatementLine([m.ZeroOrMore(empty_statement)]))]
45+
),
46+
# same-line statement[s]
47+
m.SimpleStatementSuite(body=[m.ZeroOrMore(empty_statement)]),
4248
),
4349
)
4450

@@ -114,12 +120,10 @@ def __init__(self):
114120

115121
@property
116122
@abstractmethod
117-
def library(self) -> tuple[str, ...]:
118-
...
123+
def library(self) -> tuple[str, ...]: ...
119124

120125
@abstractmethod
121-
def should_autofix(self, node: cst.CSTNode, code: str | None = None) -> bool:
122-
...
126+
def should_autofix(self, node: cst.CSTNode, code: str | None = None) -> bool: ...
123127

124128
# instead of trying to exclude yields found in all the weird places from
125129
# setting self.add_statement, we instead clear it upon each new line.
@@ -587,7 +591,10 @@ def visit_While_body(self, node: cst.For | cst.While):
587591
if getattr(node, "asynchronous", None):
588592
self.uncheckpointed_statements = set()
589593
else:
590-
self.uncheckpointed_statements = {ARTIFICIAL_STATEMENT}
594+
# pyright correctly dislikes Statement defining __eq__ but not __hash__
595+
# but it works:tm:, and changing it touches on various bits of code, so
596+
# leaving it for another time.
597+
self.uncheckpointed_statements = {ARTIFICIAL_STATEMENT} # pyright: ignore
591598

592599
self.loop_state.uncheckpointed_before_continue = set()
593600
self.loop_state.uncheckpointed_before_break = set()

flake8_trio/visitors/visitor_utility.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import ast
66
import functools
77
import re
8-
from typing import TYPE_CHECKING, Any
8+
from typing import TYPE_CHECKING, Any, cast
99

1010
import libcst.matchers as m
1111
from libcst.metadata import PositionProvider
@@ -17,6 +17,7 @@
1717
from re import Match
1818

1919
import libcst as cst
20+
from libcst._position import CodeRange
2021

2122

2223
@utility_visitor
@@ -178,7 +179,10 @@ def visit_Comment(self, node: cst.Comment):
178179
return False
179180

180181
codes_str = noqa_match.groupdict()["codes"]
181-
pos = self.get_metadata(PositionProvider, node).start
182+
183+
# see https://github.com/Instagram/LibCST/issues/1107
184+
metadata = cast("CodeRange", self.get_metadata(PositionProvider, node))
185+
pos = metadata.start
182186

183187
codes: set[str]
184188

0 commit comments

Comments
 (0)