ruff
8f703fcb - [`refurb`] Skip `FURB101` and `FURB103` when the `open` argument is a file descriptor (#27643)

Commit
27 days ago
[`refurb`] Skip `FURB101` and `FURB103` when the `open` argument is a file descriptor (#27643) ## Summary The core issue is that `pathlib.Path` does not accept a file descriptor. This results in a safe fix that breaks at runtime. On top of that, `find_file_open` in refurb never received this check. `FURB101` and `FURB103` both go through `find_file_opens`. There is precedent for this cross-plugin import: `flake8_blind_except` imports from `flake8_logging`'s helpers, and `flake8_pyi` from `flake8_type_checking`'s. The scope is integer literals, names annotated as `int`, and class attributes annotated as `int`. `os.open(...)` is excluded because it requires type inference. One last thing: this is unrelated to the `FURB103` truncation issue (astral-sh/ruff#26920), which stays open. This PR covers only the file descriptor case. #26922 remains open to track the bytes case. ## Test Plan The most important data point is that 2812 tests pass. The cases are added at the end of `FURB101_0.py` and `FURB103_0.py` (the `str` control is still reported). Zero pre-existing diagnostics were altered — `git diff -U0 <snapshots> | grep '^-'` comes out **empty**. `cargo dev generate-all` is still up to date. --------- Co-authored-by: Brent Westbrook <brentrwestbrook@gmail.com>
Parents
Loading