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

PTH123 shadows ASYNC101 and SIM115 #6892

Closed
Olegt0rr opened this issue Aug 26, 2023 · 3 comments
Closed

PTH123 shadows ASYNC101 and SIM115 #6892

Olegt0rr opened this issue Aug 26, 2023 · 3 comments
Labels
bug Something isn't working rule Implementing or modifying a lint rule

Comments

@Olegt0rr
Copy link

Let's ruff:

async def foo() -> None:
    """Open something."""
    open("foo")

Result:

ASYNC101 Async functions should not call `open`, `time.sleep`, or `subprocess` methods
SIM115 Use context handler for opening files
PTH123 `open()` should be replaced by `Path.open()`

Let's apply fix for PTH123 and ruff it again:

async def foo() -> None:
    """Open something."""
    path = Path("foo")
    path.open("foo")

Result: success

Expected:

  • ASYNC101 (cause path.open is also blocking as open for async.)
  • SIM115 (cause path.open works the same as open)
@zanieb
Copy link
Member

zanieb commented Aug 26, 2023

Sounds like PTH123 needs to be updated to be async aware and ASYNC101 should probably raise on Path.open too?

@zanieb zanieb added bug Something isn't working rule Implementing or modifying a lint rule labels Aug 26, 2023
@Olegt0rr
Copy link
Author

That's right, but it doesn't seem so easy to catch path.open(), since the Path object can be named differently.

@charliermarsh
Copy link
Member

Gonna call this one closed by #9703.

charliermarsh pushed a commit that referenced this issue Jan 30, 2024
…c functions (#9703)

## Summary

This review contains a fix for
[ASYNC101](https://docs.astral.sh/ruff/rules/open-sleep-or-subprocess-in-async-function/)
(open-sleep-or-subprocess-in-async-function)

The problem is that ruff does not take open calls from pathlib.Path into
account in async functions. Path.open() call is still a blocking call.
In addition, PTH123 suggests to use pathlib.Path instead of os.open. So
this might create an additional confusion.

See: #6892

## Test Plan

```bash
cargo test
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working rule Implementing or modifying a lint rule
Projects
None yet
Development

No branches or pull requests

3 participants