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

very preliminary unshielded await rule #14370

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

altendky
Copy link

@altendky altendky commented Nov 15, 2024

Summary

When working with async cleanup activities it is important to be aware of shielding the cleanup from cancellation.

https://anyio.readthedocs.io/en/stable/cancellation.html#shielding

This rule looks for unshielded awaits in relevant cleanup paths such as exception handling and finally blocks. It walks the AST looking for awaits but prunes when it finds shielding context managers.

Test Plan

Copy link
Contributor

github-actions bot commented Nov 15, 2024

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+54 -2430 violations, +0 -0 fixes in 11 projects; 43 projects unchanged)

DisnakeDev/disnake (+14 -3 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview

+ disnake/client.py:1289:17: RUF102 shield it!
+ disnake/client.py:732:9: RUF102 shield it!
+ disnake/ext/commands/base_core.py:325:9: RUF102 shield it!
+ disnake/ext/commands/base_core.py:401:13: RUF102 shield it!
+ disnake/ext/commands/core.py:1463:17: RUF102 shield it!
+ disnake/ext/commands/core.py:155:13: RUF102 shield it!
... 9 additional changes omitted for rule RUF102
- disnake/ext/tasks/__init__.py:278:14: RUF021 [*] Parenthesize `a and b` expressions when chaining `and` and `or` together, to make the precedence clear
- disnake/ext/tasks/__init__.py:53:17: RUF023 [*] `SleepHandle.__slots__` is not sorted
- disnake/shard.py:64:17: RUF023 [*] `EventItem.__slots__` is not sorted
... 8 additional changes omitted for project

RasaHQ/rasa (+4 -4 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview

+ rasa/core/brokers/pika.py:211:13: RUF102 shield it!
+ rasa/core/channels/facebook.py:164:13: RUF102 shield it!
- rasa/core/tracker_store.py:1061:9: D107 Missing docstring in `__init__`
- rasa/core/tracker_store.py:1131:9: D205 1 blank line required between summary line and description
- rasa/core/tracker_store.py:280:9: D205 1 blank line required between summary line and description
- rasa/core/tracker_store.py:769:9: D107 Missing docstring in `__init__`
+ tests/integration_tests/core/brokers/test_pika.py:150:9: RUF102 shield it!
+ tests/integration_tests/core/brokers/test_pika.py:33:9: RUF102 shield it!

apache/airflow (+8 -1297 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview --select ALL

+ airflow/jobs/triggerer_job_runner.py:655:13: RUF102 shield it!
- providers/src/airflow/providers/amazon/aws/hooks/elasticache_replication_group.py:100:9: D212 [*] Multi-line docstring summary should start at the first line
- providers/src/airflow/providers/amazon/aws/hooks/elasticache_replication_group.py:109:9: DOC201 `return` is not documented in docstring
- providers/src/airflow/providers/amazon/aws/hooks/elasticache_replication_group.py:112:9: D212 [*] Multi-line docstring summary should start at the first line
- providers/src/airflow/providers/amazon/aws/hooks/elasticache_replication_group.py:118:9: DOC201 `return` is not documented in docstring
- providers/src/airflow/providers/amazon/aws/hooks/elasticache_replication_group.py:127:9: D212 [*] Multi-line docstring summary should start at the first line
- providers/src/airflow/providers/amazon/aws/hooks/elasticache_replication_group.py:151:101: COM812 [*] Trailing comma missing
- providers/src/airflow/providers/amazon/aws/hooks/elasticache_replication_group.py:170:13: DOC201 `return` is not documented in docstring
- providers/src/airflow/providers/amazon/aws/hooks/elasticache_replication_group.py:174:9: ANN201 Missing return type annotation for public function `wait_for_deletion`
- providers/src/airflow/providers/amazon/aws/hooks/elasticache_replication_group.py:181:9: D212 [*] Multi-line docstring summary should start at the first line
- providers/src/airflow/providers/amazon/aws/hooks/elasticache_replication_group.py:1:1: CPY001 Missing copyright notice at top of file
- providers/src/airflow/providers/amazon/aws/hooks/elasticache_replication_group.py:1:1: D100 Missing docstring in public module
- providers/src/airflow/providers/amazon/aws/hooks/elasticache_replication_group.py:205:105: COM812 [*] Trailing comma missing
- providers/src/airflow/providers/amazon/aws/hooks/elasticache_replication_group.py:247:9: DOC201 `return` is not documented in docstring
- providers/src/airflow/providers/amazon/aws/hooks/elasticache_replication_group.py:256:9: D212 [*] Multi-line docstring summary should start at the first line
- providers/src/airflow/providers/amazon/aws/hooks/elasticache_replication_group.py:279:19: DOC501 Raised exception `AirflowException` missing from docstring
- providers/src/airflow/providers/amazon/aws/hooks/elasticache_replication_group.py:279:19: TRY003 Avoid specifying long messages outside the exception class
- providers/src/airflow/providers/amazon/aws/hooks/elasticache_replication_group.py:279:36: EM102 Exception must not use an f-string literal, assign to variable first
- providers/src/airflow/providers/amazon/aws/hooks/elasticache_replication_group.py:27:5: D212 [*] Multi-line docstring summary should start at the first line
... 178 additional changes omitted for rule D212
- providers/src/airflow/providers/amazon/aws/hooks/elasticache_replication_group.py:281:9: DOC201 `return` is not documented in docstring
- providers/src/airflow/providers/amazon/aws/hooks/elasticache_replication_group.py:48:9: ANN204 Missing return type annotation for special method `__init__`
- providers/src/airflow/providers/amazon/aws/hooks/elasticache_replication_group.py:48:9: D107 Missing docstring in `__init__`
- providers/src/airflow/providers/amazon/aws/hooks/elasticache_replication_group.py:53:9: ANN002 Missing type annotation for `*args`
- providers/src/airflow/providers/amazon/aws/hooks/elasticache_replication_group.py:54:9: ANN003 Missing type annotation for `**kwargs`
- providers/src/airflow/providers/amazon/aws/hooks/elasticache_replication_group.py:73:9: DOC201 `return` is not documented in docstring
... 154 additional changes omitted for rule DOC201
- providers/src/airflow/providers/amazon/aws/hooks/emr.py:136:16: RET504 Unnecessary assignment to `response` before `return` statement
... 1279 additional changes omitted for project

apache/superset (+0 -152 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview --select ALL

- superset/migrations/versions/2015-12-04_09-42_1a48a5411020_adding_slug_to_dash.py:17:1: D400 First line should end with a period
- superset/migrations/versions/2015-12-04_09-42_1a48a5411020_adding_slug_to_dash.py:17:1: D415 First line should end with a period, question mark, or exclamation point
- superset/migrations/versions/2015-12-04_09-42_1a48a5411020_adding_slug_to_dash.py:1:1: CPY001 Missing copyright notice at top of file
- superset/migrations/versions/2015-12-04_09-42_1a48a5411020_adding_slug_to_dash.py:1:1: N999 Invalid module name: '2015-12-04_09-42_1a48a5411020_adding_slug_to_dash'
- superset/migrations/versions/2015-12-04_09-42_1a48a5411020_adding_slug_to_dash.py:33:5: ANN201 Missing return type annotation for public function `upgrade`
- superset/migrations/versions/2015-12-04_09-42_1a48a5411020_adding_slug_to_dash.py:33:5: D103 Missing docstring in public function
- superset/migrations/versions/2015-12-04_09-42_1a48a5411020_adding_slug_to_dash.py:35:5: SIM105 Use `contextlib.suppress(Exception)` instead of `try`-`except`-`pass`
- superset/migrations/versions/2015-12-04_09-42_1a48a5411020_adding_slug_to_dash.py:37:5: S110 `try`-`except`-`pass` detected, consider logging the exception
- superset/migrations/versions/2015-12-04_09-42_1a48a5411020_adding_slug_to_dash.py:41:5: ANN201 Missing return type annotation for public function `downgrade`
- superset/migrations/versions/2015-12-04_09-42_1a48a5411020_adding_slug_to_dash.py:41:5: D103 Missing docstring in public function
... 142 additional changes omitted for project

latchbio/latch (+2 -116 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview

- src/latch/ldata/_transfer/upload.py:109:52: A001 Variable `exec` is shadowing a Python builtin
- src/latch/ldata/_transfer/upload.py:109:5: SIM117 Use a single `with` statement with multiple contexts instead of nested `with` statements
- src/latch/ldata/_transfer/upload.py:10:38: TCH003 Move standard library import `multiprocessing.managers.DictProxy` into a type-checking block
- src/latch/ldata/_transfer/upload.py:10:49: TCH003 Move standard library import `multiprocessing.managers.ListProxy` into a type-checking block
- src/latch/ldata/_transfer/upload.py:111:27: UP037 [*] Remove quotes from type annotation
- src/latch/ldata/_transfer/upload.py:112:33: UP037 [*] Remove quotes from type annotation
- src/latch/ldata/_transfer/upload.py:118:23: UP006 Use `list` instead of `List` for type annotation
- src/latch/ldata/_transfer/upload.py:122:28: UP037 [*] Remove quotes from type annotation
- src/latch/ldata/_transfer/upload.py:12:19: TCH003 Move standard library import `queue.Queue` into a type-checking block
- src/latch/ldata/_transfer/upload.py:13:1: UP035 `typing.List` is deprecated, use `list` instead
... 108 additional changes omitted for project

lnbits/lnbits (+10 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview

+ lnbits/tasks.py:83:5: RUF102 shield it!
+ lnbits/wallets/blink.py:314:13: RUF102 shield it!
+ lnbits/wallets/boltz.py:209:13: RUF102 shield it!
+ lnbits/wallets/cliche.py:181:13: RUF102 shield it!
+ lnbits/wallets/corelightning.py:263:13: RUF102 shield it!
+ lnbits/wallets/corelightningrest.py:315:13: RUF102 shield it!
+ lnbits/wallets/eclair.py:243:13: RUF102 shield it!
+ lnbits/wallets/lndgrpc.py:280:13: RUF102 shield it!
+ lnbits/wallets/lndrest.py:288:13: RUF102 shield it!
+ lnbits/wallets/phoenixd.py:240:13: RUF102 shield it!

pandas-dev/pandas (+0 -4 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview

- pandas/io/pytables.py:2795:17: PLR6104 Use `+=` to perform an augmented assignment directly
- pandas/io/pytables.py:4511:17: PLR6104 Use `&=` to perform an augmented assignment directly
- pandas/tests/io/excel/test_readers.py:112:13: F841 Local variable `read_ext` is assigned to but never used
- pandas/tests/io/excel/test_readers.py:118:5: F841 Local variable `engine` is assigned to but never used

... Truncated remaining completed project reports due to GitHub comment length restrictions

Changes by rule (145 rules affected)

code total + violation - violation + fix - fix
COM812 226 0 226 0 0
D212 221 0 221 0 0
DOC201 198 0 198 0 0
ANN201 119 0 119 0 0
PLR6301 93 0 93 0 0
ANN001 92 0 92 0 0
D102 85 0 85 0 0
TRY003 63 0 63 0 0
PLC0415 61 0 61 0 0
D205 56 0 56 0 0
RUF102 54 54 0 0 0
ANN401 46 0 46 0 0
DOC501 45 0 45 0 0
D103 43 0 43 0 0
TRY400 37 0 37 0 0
EM102 35 0 35 0 0
FBT001 35 0 35 0 0
PLC1901 35 0 35 0 0
RUF012 34 0 34 0 0
FBT002 33 0 33 0 0
D107 31 0 31 0 0
RET505 31 0 31 0 0
E501 31 0 31 0 0
D101 31 0 31 0 0
ARG002 30 0 30 0 0
S101 30 0 30 0 0
EM101 28 0 28 0 0
D401 27 0 27 0 0
CPY001 26 0 26 0 0
ANN003 26 0 26 0 0
ANN202 22 0 22 0 0
ANN204 21 0 21 0 0
TRY300 21 0 21 0 0
B904 21 0 21 0 0
PLR0913 19 0 19 0 0
PLR6201 18 0 18 0 0
D100 17 0 17 0 0
BLE001 17 0 17 0 0
PLR0917 14 0 14 0 0
D400 14 0 14 0 0
D415 14 0 14 0 0
FA100 14 0 14 0 0
C901 13 0 13 0 0
RET504 12 0 12 0 0
D404 12 0 12 0 0
PLC2701 11 0 11 0 0
ANN002 10 0 10 0 0
PLR0912 10 0 10 0 0
UP006 10 0 10 0 0
ARG001 10 0 10 0 0
D202 9 0 9 0 0
SIM103 9 0 9 0 0
PLR0911 8 0 8 0 0
D209 8 0 8 0 0
PLR2004 7 0 7 0 0
FBT003 7 0 7 0 0
PTH123 7 0 7 0 0
SLF001 7 0 7 0 0
F841 7 0 7 0 0
C408 7 0 7 0 0
TRY201 6 0 6 0 0
FIX002 6 0 6 0 0
TD002 6 0 6 0 0
TD003 6 0 6 0 0
PLR0915 6 0 6 0 0
D200 6 0 6 0 0
PGH003 5 0 5 0 0
RET506 5 0 5 0 0
RET503 5 0 5 0 0
PLW1514 5 0 5 0 0
S110 5 0 5 0 0
LOG015 5 0 5 0 0
S607 5 0 5 0 0
PLR0904 4 0 4 0 0
DTZ005 4 0 4 0 0
T201 4 0 4 0 0
N999 4 0 4 0 0
N806 4 0 4 0 0
PLW1641 4 0 4 0 0
PERF203 3 0 3 0 0
SIM102 3 0 3 0 0
SIM910 3 0 3 0 0
FURB110 3 0 3 0 0
SIM108 3 0 3 0 0
FURB101 3 0 3 0 0
SIM105 3 0 3 0 0
A001 3 0 3 0 0
TCH003 3 0 3 0 0
UP037 3 0 3 0 0
UP035 3 0 3 0 0
I001 3 0 3 0 0
RUF023 2 0 2 0 0
B026 2 0 2 0 0
PYI041 2 0 2 0 0
PLR5501 2 0 2 0 0
PTH118 2 0 2 0 0
PLW2901 2 0 2 0 0
B009 2 0 2 0 0
PLR1702 2 0 2 0 0
ANN205 2 0 2 0 0
S113 2 0 2 0 0
ERA001 2 0 2 0 0
S311 2 0 2 0 0
FURB103 2 0 2 0 0
SIM117 2 0 2 0 0
S404 2 0 2 0 0
PLW1510 2 0 2 0 0
E722 2 0 2 0 0
UP015 2 0 2 0 0
PLR6104 2 0 2 0 0
PLR0914 2 0 2 0 0
PT018 2 0 2 0 0
RUF021 1 0 1 0 0
PLR1733 1 0 1 0 0
FURB118 1 0 1 0 0
RET508 1 0 1 0 0
DOC402 1 0 1 0 0
PTH112 1 0 1 0 0
PTH119 1 0 1 0 0
PYI024 1 0 1 0 0
SIM118 1 0 1 0 0
D405 1 0 1 0 0
D413 1 0 1 0 0
PLR1714 1 0 1 0 0
RUF035 1 0 1 0 0
PTH113 1 0 1 0 0
PLR1722 1 0 1 0 0
RUF032 1 0 1 0 0
C419 1 0 1 0 0
TRY002 1 0 1 0 0
TCH002 1 0 1 0 0
N812 1 0 1 0 0
PERF401 1 0 1 0 0
RET502 1 0 1 0 0
D417 1 0 1 0 0
FURB188 1 0 1 0 0
PLE0704 1 0 1 0 0
PTH101 1 0 1 0 0
PLC0206 1 0 1 0 0
D106 1 0 1 0 0
S105 1 0 1 0 0
FIX004 1 0 1 0 0
TCH001 1 0 1 0 0
PLW3201 1 0 1 0 0
PYI066 1 0 1 0 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant