Skip to content
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

ASYNC912: timeout/cancelscope with only conditional checkpoints #242

Merged
merged 6 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Changelog
*[CalVer, YY.month.patch](https://calver.org/)*

## 24.5.1
- Add ASYNC912: no checkpoints in with statement are guaranteed to run.

## 24.4.1
- ASYNC91X fix internal error caused by multiple `try/except` incorrectly sharing state.
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Note: 22X, 23X and 24X has not had asyncio-specific suggestions written.
- **ASYNC910**: Exit or `return` from async function with no guaranteed checkpoint or exception since function definition. You might want to enable this on a codebase to make it easier to reason about checkpoints, and make the logic of ASYNC911 correct.
- **ASYNC911**: Exit, `yield` or `return` from async iterable with no guaranteed checkpoint since possible function entry (yield or function definition)
Checkpoints are `await`, `async for`, and `async with` (on one of enter/exit).
- **ASYNC912**: TODO: write

### Removed Warnings
- **TRIOxxx**: All error codes are now renamed ASYNCxxx
Expand Down
2 changes: 1 addition & 1 deletion flake8_async/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@


# CalVer: YY.month.patch, e.g. first release of July 2022 == "22.7.1"
__version__ = "24.4.1"
__version__ = "24.5.1"


# taken from https://github.com/Zac-HD/shed
Expand Down
1 change: 0 additions & 1 deletion flake8_async/visitors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
from . import (
visitor2xx,
visitor91x,
visitor100,
visitor101,
visitor102,
visitor103_104,
Expand Down
12 changes: 10 additions & 2 deletions flake8_async/visitors/flake8asyncvisitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@ def error(
), "No error code defined, but class has multiple codes"
error_code = next(iter(self.error_codes))
# don't emit an error if this code is disabled in a multi-code visitor
elif strip_error_subidentifier(error_code) not in self.options.enabled_codes:
elif (
(ec_no_sub := strip_error_subidentifier(error_code))
not in self.options.enabled_codes
and ec_no_sub not in self.options.autofix_codes
):
Comment on lines -101 to +105
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not great that there's duplication of logic between the visitors (it confused me for a bit while developing). I originally expected all visitors to be rewritten to use libcst, but given that's not going to happen anytime soon (or at all), I should probably refactor these two and put common code in a parent class.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me 👍

return

self.__state.problems.append(
Expand Down Expand Up @@ -217,7 +221,11 @@ def error(
error_code = next(iter(self.error_codes))
# don't emit an error if this code is disabled in a multi-code visitor
# TODO: write test for only one of 910/911 enabled/autofixed
elif strip_error_subidentifier(error_code) not in self.options.enabled_codes:
elif (
(ec_no_sub := strip_error_subidentifier(error_code))
not in self.options.enabled_codes
and ec_no_sub not in self.options.autofix_codes
):
return False # pragma: no cover

if self.is_noqa(node, error_code):
Expand Down
6 changes: 6 additions & 0 deletions flake8_async/visitors/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ def disabled_by_default(error_class: type[T_EITHER]) -> type[T_EITHER]:
return error_class


def disable_codes_by_default(*codes: str) -> None:
default_disabled_error_codes.extend(codes)


def utility_visitor(c: type[T]) -> type[T]:
assert not hasattr(c, "error_codes")
c.error_codes = {}
Expand Down Expand Up @@ -320,6 +324,8 @@ class AttributeCall(NamedTuple):
def with_has_call(
node: cst.With, *names: str, base: Iterable[str] = ("trio", "anyio")
) -> list[AttributeCall]:
if isinstance(base, str):
base = (base,)
res_list: list[AttributeCall] = []
for item in node.items:
if res := m.extract(
Expand Down
90 changes: 0 additions & 90 deletions flake8_async/visitors/visitor100.py

This file was deleted.

Loading