-
-
Notifications
You must be signed in to change notification settings - Fork 10
Add ASYNC233 pathlib blocking call rule #467
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
Open
paranoa233
wants to merge
3
commits into
python-trio:main
Choose a base branch
from
paranoa233:fix-pathlib-blocking-async233
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -190,6 +190,9 @@ ASYNC231 : blocking-fdopen-call | |
| ASYNC232 : blocking-file-call | ||
| Blocking sync call on file object, wrap the file object in :func:`trio.wrap_file`/:func:`anyio.wrap_file` to get an async file object. | ||
|
|
||
| _`ASYNC233` : blocking-pathlib-call | ||
| 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`_. | ||
|
Comment on lines
+194
to
197
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think in each case I'd recommend that It's fine if you'd rather leave that for someone else's later PR though. |
||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| # ARG --enable=ASYNC233 | ||
| # NOASYNCIO # see async233_asyncio.py | ||
| import pathlib | ||
| from pathlib import Path | ||
| from pathlib import PosixPath as UnixPath | ||
|
|
||
| import trio | ||
|
|
||
|
|
||
| async def foo(path: Path, other_path: pathlib.Path): | ||
| path.open() # ASYNC233: 4, 'path.open', "trio" | ||
| path.read_text() # ASYNC233: 4, 'path.read_text', "trio" | ||
| path.read_bytes() # ASYNC233: 4, 'path.read_bytes', "trio" | ||
| path.write_text("content") # ASYNC233: 4, 'path.write_text', "trio" | ||
| path.write_bytes(b"content") # ASYNC233: 4, 'path.write_bytes', "trio" | ||
| path.touch() # ASYNC233: 4, 'path.touch', "trio" | ||
|
|
||
| other_path.read_text() # ASYNC233: 4, 'other_path.read_text', "trio" | ||
| Path("foo").read_text() # ASYNC233: 4, "Path('foo').read_text", "trio" | ||
| module_path = pathlib.Path("foo") | ||
| module_path.read_bytes() # ASYNC233: 4, 'module_path.read_bytes', "trio" | ||
| cwd = pathlib.Path.cwd() | ||
| cwd.write_text("content") # ASYNC233: 4, 'cwd.write_text', "trio" | ||
| UnixPath("foo").touch() # ASYNC233: 4, "UnixPath('foo').touch", "trio" | ||
|
|
||
| assigned = Path("foo") | ||
| assigned.write_bytes(b"content") # ASYNC233: 4, 'assigned.write_bytes', "trio" | ||
|
|
||
| await path.read_text() | ||
| await trio.wrap_file(path.open()) | ||
| path.with_suffix(".txt") | ||
|
|
||
|
|
||
| def foo_sync(path: Path): | ||
| path.read_text() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| # ARG --enable=ASYNC233 | ||
| # NOTRIO # see async233.py | ||
| # NOANYIO # see async233.py | ||
| # BASE_LIBRARY asyncio | ||
| from pathlib import Path | ||
|
|
||
|
|
||
| async def foo(path: Path): | ||
| path.read_text() # ASYNC233_asyncio: 4, 'path.read_text' | ||
| Path("foo").write_text("content") # ASYNC233_asyncio: 4, "Path('foo').write_text" | ||
|
|
||
|
|
||
| def foo_sync(path: Path): | ||
| path.read_text() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.