Skip to content

Add ASYNC233 pathlib blocking call rule - #467

Open
paranoa233 wants to merge 3 commits into
python-trio:mainfrom
paranoa233:fix-pathlib-blocking-async233
Open

Add ASYNC233 pathlib blocking call rule#467
paranoa233 wants to merge 3 commits into
python-trio:mainfrom
paranoa233:fix-pathlib-blocking-async233

Conversation

@paranoa233

Copy link
Copy Markdown
Contributor

Closes #396.

Summary

  • add ASYNC233 for blocking pathlib.Path I/O methods in async functions
  • track pathlib Path values from annotations and common constructors
  • document the new rule and add changelog coverage

Test Plan

  • python -m pytest tests/test_flake8_async.py -k "ASYNC233 or ASYNC212"
  • python -m pytest tests/test_messages_documented.py tests/test_all_visitors_imported.py
  • python -m ruff check flake8_async tests docs

Full python -m pytest on Windows: 1180 passed, 170 skipped; 2 existing CLI-output assertions fail because local subprocess output uses CRLF/path separators.

@Zac-HD Zac-HD left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Small docs and changelog note; otherwise looks great - thanks @paranoa233!

Comment thread docs/changelog.rst

26.6.1
======
- Add :ref:`ASYNC233 <async233>` blocking-pathlib-call to detect blocking ``pathlib.Path`` I/O methods in async functions. `(issue #396) <https://github.com/python-trio/flake8-async/issues/396>`_

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

new heading for this (26.7.2 - you might want to rebase), since it'll be a new release.

Comment thread docs/rules.rst
Comment on lines +194 to 197
Blocking sync call to ``pathlib.Path`` I/O methods in async function, use :class:`trio.Path`/:class:`anyio.Path`. ``asyncio`` users should consider `aiopath <https://pypi.org/project/aiopath>`__ or `anyio`_.

ASYNC240 : blocking-path-usage
Avoid using :mod:`os.path` in async functions, prefer using :class:`trio.Path`/:class:`anyio.Path` objects. ``asyncio`` users should consider `aiopath <https://pypi.org/project/aiopath>`__ or `anyio`_.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think in each case I'd recommend that asyncio users use anyio.Path objects on asyncio backend (it's automatic and therefore easy), rather than aio- libs; I just can't trust the latter as much.

It's fine if you'd rather leave that for someone else's later PR though.

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.

New rule: ASYNC233 for blocking pathlib methods

2 participants