Skip to content

remove lines from autofix diff, add CI tag management #164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,6 @@ jobs:
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }}
run: python -m build && twine upload --skip-existing dist/*
run: |
python tests/test_version_and_changelog.py --ensure-tag
python -m build && twine upload --skip-existing dist/*
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ repos:
# Required for pyright strict mode
- anyio
- flake8
- GitPython
- hypothesis
- hypothesmith
- pytest
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

## Future
- TRIO91X now supports comprehensions
- TRIO100 and TRIO91X now supports autofixing
- Renamed `--enable-visitor-codes-regex` to `--enable`
- Added `--disable`, `--autofix` and `--error-on-autofix`

## 23.2.5
- Fix false alarms for `@pytest.fixture`-decorated functions in TRIO101, TRIO910 and TRIO911
Expand Down
36 changes: 35 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,23 @@ pip install flake8-trio

## Configuration
[You can configure `flake8` with command-line options](https://flake8.pycqa.org/en/latest/user/configuration.html),
but we prefer using a config file. The file needs to start with a section marker `[flake8]` and the following options are then parsed using flake8's config parser, and can be used just like any other flake8 options.
but we prefer using a config file. The file needs to start with a section marker `[flake8]` and the following options are then parsed using flake8's config parser, and can be used just like any other flake8 options.
Note that it's not currently possible to use a configuration file when running flake8_trio standalone.

### `--enable`
Comma-separated list of error codes to enable, similar to flake8 --select but is additionally more performant as it will disable non-enabled visitors from running instead of just silencing their errors.

### `--disable`
Comma-separated list of error codes to disable, similar to flake8 --ignore but is additionally more performant as it will disable non-enabled visitors from running instead of just silencing their errors.

### `--autofix`
Comma-separated list of error-codes to enable autofixing for if implemented. Requires running as a standalone program.

### `--error-on-autofix`
Whether to also print an error message for autofixed errors.

### `--anyio`
Change the default library to be anyio instead of trio. If trio is imported it will assume both are available and print suggestions with [anyio|trio].

### `no-checkpoint-warning-decorators`
Specify a list of decorators to disable checkpointing checks for, turning off TRIO910 and TRIO911 warnings for functions decorated with any decorator matching any in the list. Matching is done with [fnmatch](https://docs.python.org/3/library/fnmatch.html). Defaults to disabling for `asynccontextmanager`.
Expand Down Expand Up @@ -120,3 +136,21 @@ async def my_function():

arbitrary_other_function(my_blocking_call=None)
```


### Using flake8_trio with pre-commit
If you use [pre-commit](https://pre-commit.com/), you can use it with flake8_trio by
adding the following to your `.pre-commit-config.yaml`:

```yaml
minimum_pre_commit_version: '2.9.0'
repos:
- repo: https://github.com/Zac-HD/flake8-trio
rev: 23.2.5
hooks:
- id: flake8-trio
# args: [--enable=TRIO, --disable=TRIO9, --autofix=TRIO]
```

This is often considerably faster for large projects, because `pre-commit`
can avoid running `flake8_trio` on unchanged files.
6 changes: 3 additions & 3 deletions tests/autofix_files/trio100.py.diff
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
+++
@@ -3,24 +3,24 @@
@@ x,24 x,24 @@

import trio

Expand Down Expand Up @@ -38,7 +38,7 @@

with trio.move_on_after(10):
await trio.sleep(1)
@@ -37,8 +37,8 @@
@@ x,8 x,8 @@
with open("filename") as _:
...

Expand All @@ -49,7 +49,7 @@

send_channel, receive_channel = trio.open_memory_channel(0)
async with trio.fail_after(10):
@@ -49,22 +49,22 @@
@@ x,22 x,22 @@
async for _ in receive_channel:
...

Expand Down
2 changes: 1 addition & 1 deletion tests/autofix_files/trio100_simple_autofix.py.diff
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
+++
@@ -3,50 +3,51 @@
@@ x,50 x,51 @@

# a
# b
Expand Down
38 changes: 19 additions & 19 deletions tests/autofix_files/trio910.py.diff
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
+++
@@ -45,12 +45,14 @@
@@ x,12 x,14 @@

async def foo1(): # error: 0, "exit", Statement("function definition", lineno)
bar()
Expand All @@ -15,23 +15,23 @@


async def foo_if_2():
@@ -81,6 +83,7 @@
@@ x,6 x,7 @@

async def foo_ifexp_2(): # error: 0, "exit", Statement("function definition", lineno)
print(_ if False and await foo() else await foo())
+ await trio.lowlevel.checkpoint()


# nested function definition
@@ -89,6 +92,7 @@
@@ x,6 x,7 @@

async def foo_func_2(): # error: 4, "exit", Statement("function definition", lineno)
bar()
+ await trio.lowlevel.checkpoint()


# we don't get a newline after the nested function definition before the checkpoint
@@ -97,17 +101,21 @@
@@ x,17 x,21 @@
async def foo_func_3(): # error: 0, "exit", Statement("function definition", lineno)
async def foo_func_4():
await foo()
Expand All @@ -53,7 +53,7 @@
# fmt: on


@@ -144,11 +152,13 @@
@@ x,11 x,13 @@
async def foo_condition_2(): # error: 0, "exit", Statement("function definition", lineno)
if False and await foo():
...
Expand All @@ -67,15 +67,15 @@


async def foo_condition_4(): # safe
@@ -170,6 +180,7 @@
@@ x,6 x,7 @@
async def foo_while_1(): # error: 0, "exit", Statement("function definition", lineno)
while _:
await foo()
+ await trio.lowlevel.checkpoint()


async def foo_while_2(): # now safe
@@ -188,12 +199,14 @@
@@ x,12 x,14 @@
async def foo_while_4(): # error: 0, "exit", Statement("function definition", lineno)
while False:
await foo()
Expand All @@ -90,71 +90,71 @@


async def foo_for_2(): # now safe
@@ -216,6 +229,7 @@
@@ x,6 x,7 @@
break
else:
await foo()
+ await trio.lowlevel.checkpoint()


async def foo_while_break_3(): # error: 0, "exit", Statement("function definition", lineno)
@@ -224,6 +238,7 @@
@@ x,6 x,7 @@
break
else:
...
+ await trio.lowlevel.checkpoint()


async def foo_while_break_4(): # error: 0, "exit", Statement("function definition", lineno)
@@ -231,6 +246,7 @@
@@ x,6 x,7 @@
break
else:
...
+ await trio.lowlevel.checkpoint()


async def foo_while_continue_1(): # safe
@@ -254,6 +270,7 @@
@@ x,6 x,7 @@
continue
else:
...
+ await trio.lowlevel.checkpoint()


async def foo_while_continue_4(): # error: 0, "exit", Statement("function definition", lineno)
@@ -261,6 +278,7 @@
@@ x,6 x,7 @@
continue
else:
...
+ await trio.lowlevel.checkpoint()


async def foo_async_for_1():
@@ -299,6 +317,7 @@
@@ x,6 x,7 @@
raise
else:
await foo()
+ await trio.lowlevel.checkpoint()


async def foo_try_2(): # safe
@@ -349,6 +368,7 @@
@@ x,6 x,7 @@
pass
else:
pass
+ await trio.lowlevel.checkpoint()


async def foo_try_7(): # safe
@@ -390,6 +410,7 @@
@@ x,6 x,7 @@
await trio.sleep(0)
except:
...
+ await trio.lowlevel.checkpoint()


# safe
@@ -417,16 +438,19 @@
@@ x,16 x,19 @@
except:
...
finally:
Expand All @@ -174,15 +174,15 @@
return # error: 8, "return", Statement("function definition", lineno-2)
await foo()

@@ -435,6 +459,7 @@
@@ x,6 x,7 @@
if _:
await foo()
return # safe
+ await trio.lowlevel.checkpoint()


# loop over non-empty static collection
@@ -462,12 +487,14 @@
@@ x,12 x,14 @@
async def foo_range_4(): # error: 0, "exit", Statement("function definition", lineno)
for i in range(10, 5):
await foo()
Expand All @@ -197,7 +197,7 @@


# https://github.com/Zac-HD/flake8-trio/issues/47
@@ -551,6 +578,7 @@
@@ x,6 x,7 @@
# should error
async def foo_comprehension_2(): # error: 0, "exit", Statement("function definition", lineno)
[await foo() for x in range(10) if bar()]
Expand Down
Loading