Skip to content

[ruff] Reduce FastAPI false positives in unused-async (RUF029)#12938

Merged
AlexWaygood merged 5 commits intoastral-sh:mainfrom
TomerBin:tomer/fix-RUF029-for-fastapi
Aug 17, 2024
Merged

[ruff] Reduce FastAPI false positives in unused-async (RUF029)#12938
AlexWaygood merged 5 commits intoastral-sh:mainfrom
TomerBin:tomer/fix-RUF029-for-fastapi

Conversation

@TomerBin
Copy link
Contributor

@TomerBin TomerBin commented Aug 16, 2024

Summary

Fixes #12925.

@codspeed-hq
Copy link

codspeed-hq bot commented Aug 16, 2024

CodSpeed Performance Report

Merging #12938 will not alter performance

Comparing TomerBin:tomer/fix-RUF029-for-fastapi (058a968) with main (96802d6)

Summary

✅ 32 untouched benchmarks

@AlexWaygood
Copy link
Member

Thanks for the PR!

I've added a config option that allows FastAPI routes to be declared as async functions even when they are not doing IO operations.

Sorry, I think I might have been confusing when I mentioned configuration options in #12925 (comment). I don't think we need a configuration option here specifically regarding whether fastAPI routes should be ignored by this rule or not; that seems way too specific. I would just ignore fastAPI routes unconditionally in this rule, without adding a new configuration option.

@github-actions
Copy link
Contributor

github-actions bot commented Aug 16, 2024

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+0 -70 violations, +0 -0 fixes in 2 projects; 52 projects unchanged)

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

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

- lnbits/core/views/admin_api.py:45:11: RUF029 Function `api_monitor` is declared `async`, but doesn't `await` or use `async` features.
- lnbits/core/views/admin_api.py:88:11: RUF029 Function `api_restart_server` is declared `async`, but doesn't `await` or use `async` features.
- lnbits/core/views/admin_api.py:99:11: RUF029 Function `api_download_backup` is declared `async`, but doesn't `await` or use `async` features.
- lnbits/core/views/api.py:204:11: RUF029 Function `api_list_currencies_available` is declared `async`, but doesn't `await` or use `async` features.
- lnbits/core/views/api.py:227:11: RUF029 Function `img` is declared `async`, but doesn't `await` or use `async` features.
- lnbits/core/views/api.py:49:11: RUF029 Function `health` is declared `async`, but doesn't `await` or use `async` features.
- lnbits/core/views/api.py:58:11: RUF029 Function `api_wallets` is declared `async`, but doesn't `await` or use `async` features.
- lnbits/core/views/auth_api.py:139:11: RUF029 Function `logout` is declared `async`, but doesn't `await` or use `async` features.
- lnbits/core/views/auth_api.py:50:11: RUF029 Function `get_auth_user` is declared `async`, but doesn't `await` or use `async` features.
- lnbits/core/views/payment_api.py:257:11: RUF029 Function `api_payments_fee_reserve` is declared `async`, but doesn't `await` or use `async` features.
... 3 additional changes omitted for project

python-trio/trio (+0 -57 violations, +0 -0 fixes)

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

- src/trio/_core/_tests/test_run.py:102:15: RUF029 Function `inception` is declared `async`, but doesn't `await` or use `async` features.
- src/trio/_core/_tests/test_run.py:1209:15: RUF029 Function `crasher` is declared `async`, but doesn't `await` or use `async` features.
- src/trio/_core/_tests/test_run.py:1220:15: RUF029 Function `get_and_check_token` is declared `async`, but doesn't `await` or use `async` features.
- src/trio/_core/_tests/test_run.py:1249:15: RUF029 Function `main` is declared `async`, but doesn't `await` or use `async` features.
- src/trio/_core/_tests/test_run.py:1312:15: RUF029 Function `main` is declared `async`, but doesn't `await` or use `async` features.
- src/trio/_core/_tests/test_run.py:138:15: RUF029 Function `erroring` is declared `async`, but doesn't `await` or use `async` features.
- src/trio/_core/_tests/test_run.py:1441:15: RUF029 Function `agen` is declared `async`, but doesn't `await` or use `async` features.
- src/trio/_core/_tests/test_run.py:1555:15: RUF029 Function `child2` is declared `async`, but doesn't `await` or use `async` features.
- src/trio/_core/_tests/test_run.py:1593:15: RUF029 Function `child1` is declared `async`, but doesn't `await` or use `async` features.
- src/trio/_core/_tests/test_run.py:1610:15: RUF029 Function `func1` is declared `async`, but doesn't `await` or use `async` features.
- src/trio/_core/_tests/test_run.py:1617:15: RUF029 Function `check` is declared `async`, but doesn't `await` or use `async` features.
- src/trio/_core/_tests/test_run.py:1629:11: RUF029 Function `test_current_effective_deadline` is declared `async`, but doesn't `await` or use `async` features.
- src/trio/_core/_tests/test_run.py:1671:15: RUF029 Function `async_gen` is declared `async`, but doesn't `await` or use `async` features.
- src/trio/_core/_tests/test_run.py:174:15: RUF029 Function `crasher` is declared `async`, but doesn't `await` or use `async` features.
- src/trio/_core/_tests/test_run.py:1797:15: RUF029 Function `double_started` is declared `async`, but doesn't `await` or use `async` features.
- src/trio/_core/_tests/test_run.py:1809:15: RUF029 Function `raise_keyerror` is declared `async`, but doesn't `await` or use `async` features.
- src/trio/_core/_tests/test_run.py:1820:15: RUF029 Function `nothing` is declared `async`, but doesn't `await` or use `async` features.
- src/trio/_core/_tests/test_run.py:1849:15: RUF029 Function `started_with_no_checkpoint` is declared `async`, but doesn't `await` or use `async` features.
- src/trio/_core/_tests/test_run.py:1863:15: RUF029 Function `raise_keyerror_after_started` is declared `async`, but doesn't `await` or use `async` features.
- src/trio/_core/_tests/test_run.py:191:15: RUF029 Function `crasher` is declared `async`, but doesn't `await` or use `async` features.
- src/trio/_core/_tests/test_run.py:1989:15: RUF029 Function `fail` is declared `async`, but doesn't `await` or use `async` features.
... 35 additional changes omitted for rule RUF029
- src/trio/_core/_tests/test_run.py:49:32: A004 Import `BaseExceptionGroup` is shadowing a Python builtin
- src/trio/_core/_tests/test_run.py:49:52: A004 Import `ExceptionGroup` is shadowing a Python builtin
... 34 additional changes omitted for project

Changes by rule (2 rules affected)

code total + violation - violation + fix - fix
RUF029 68 0 68 0 0
A004 2 0 2 0 0

Copy link
Member

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

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

Sorry for the confusion about the option. Let's remove it.

@TomerBin TomerBin force-pushed the tomer/fix-RUF029-for-fastapi branch from 1d3d8d5 to d52206a Compare August 17, 2024 12:48
@TomerBin TomerBin force-pushed the tomer/fix-RUF029-for-fastapi branch from d52206a to 047d6bf Compare August 17, 2024 12:50
@TomerBin TomerBin force-pushed the tomer/fix-RUF029-for-fastapi branch from 047d6bf to dab4e12 Compare August 17, 2024 12:59
Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

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

Thanks!

@AlexWaygood AlexWaygood changed the title Reduce FastAPI false positives in RUF029 [ruff] Reduce FastAPI false positives in unused-async (RUF029) Aug 17, 2024
@AlexWaygood AlexWaygood dismissed MichaReiser’s stale review August 17, 2024 14:22

review comments were addressed

@AlexWaygood AlexWaygood enabled auto-merge (squash) August 17, 2024 14:22
@AlexWaygood AlexWaygood merged commit 52ba941 into astral-sh:main Aug 17, 2024
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.

RUF029 gives false positives with FastApi routes

3 participants