Skip to content

PTH123 wrongly suggests Path.open() for file descriptors, only sometimes #17691

Closed
@sbrudenell

Description

@sbrudenell

Summary

fp = open(1)
def f() -> int:
    return 1
fp = open(f())
def g(x: int) -> None:
    open(x)
r = 1
fp = open(r)
$ ruff --version
ruff 0.11.7
$ ruff check --isolated --select PTH123 t.py
t.py:4:6: PTH123 `open()` should be replaced by `Path.open()`
  |
2 | def f() -> int:
3 |     return 1
4 | fp = open(f())
  |      ^^^^ PTH123
5 | def g(x: int) -> None:
6 |     open(x)
  |

Found 1 error.

This doesn't look like a regression of #12871. But I guess the fix (#13616) somehow didn't cover the case where the argument of open() is an int return value?

Version

0.11.7

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedContributions especially welcomeruleImplementing or modifying a lint rule

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions