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

Find typos with codespell and lint Python code with ruff #171

Closed
wants to merge 2 commits into from

Conversation

cclauss
Copy link
Contributor

@cclauss cclauss commented Jul 23, 2024

https://github.com/codespell-project/codespell and https://docs.astral.sh/ruff

Should we add a dependency on https://pypi.org/project/anyio to demonstrate the best practice?

% ruff rule ASYNC230

blocking-open-call-in-async-function (ASYNC230)

Derived from the flake8-async linter.

What it does

Checks that async functions do not open files with blocking methods like open.

Why is this bad?

Blocking an async function via a blocking call will block the entire
event loop, preventing it from executing other tasks while waiting for the
call to complete, negating the benefits of asynchronous programming.

Instead of making a blocking call, use an equivalent asynchronous library
or function.

Example

async def foo():
    with open("bar.txt") as f:
        contents = f.read()

Use instead:

import anyio


async def foo():
    async with await anyio.open_file("bar.txt") as f:
        contents = await f.read()

@cclauss cclauss force-pushed the codespell-and-ruff branch from c935787 to a98f3a7 Compare July 23, 2024 12:12
@cclauss cclauss closed this Feb 8, 2025
@cclauss cclauss deleted the codespell-and-ruff branch February 8, 2025 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

1 participant