-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[
flake8-simplify
] - extend open-file-with-context-handler to work w…
…ith `tempfile` (`SIM115`)
- Loading branch information
1 parent
900e98b
commit ed49437
Showing
3 changed files
with
52 additions
and
67 deletions.
There are no files selected for viewing
This file contains 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 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
76 changes: 32 additions & 44 deletions
76
...ake8_simplify/snapshots/ruff_linter__rules__flake8_simplify__tests__SIM115_SIM115.py.snap
This file contains 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 |
---|---|---|
@@ -1,63 +1,51 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/flake8_simplify/mod.rs | ||
--- | ||
SIM115.py:8:5: SIM115 Use context handler for opening files | ||
| | ||
7 | # SIM115 | ||
8 | f = open("foo.txt") | ||
| ^^^^ SIM115 | ||
9 | f = Path("foo.txt").open() | ||
10 | f = pathlib.Path("foo.txt").open() | ||
| | ||
|
||
SIM115.py:9:5: SIM115 Use context handler for opening files | ||
| | ||
7 | # SIM115 | ||
8 | f = open("foo.txt") | ||
9 | f = Path("foo.txt").open() | ||
| ^^^^^^^^^^^^^^^^^^^^ SIM115 | ||
10 | f = pathlib.Path("foo.txt").open() | ||
11 | f = pl.Path("foo.txt").open() | ||
8 | # SIM115 | ||
9 | f = open("foo.txt") | ||
| ^^^^ SIM115 | ||
10 | f = Path("foo.txt").open() | ||
11 | f = pathlib.Path("foo.txt").open() | ||
| | ||
|
||
SIM115.py:10:5: SIM115 Use context handler for opening files | ||
SIM115.py:14:5: SIM115 Use context handler for opening files | ||
| | ||
8 | f = open("foo.txt") | ||
9 | f = Path("foo.txt").open() | ||
10 | f = pathlib.Path("foo.txt").open() | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SIM115 | ||
11 | f = pl.Path("foo.txt").open() | ||
12 | f = P("foo.txt").open() | ||
12 | f = pl.Path("foo.txt").open() | ||
13 | f = P("foo.txt").open() | ||
14 | f = tempfile.NamedTemporaryFile() | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ SIM115 | ||
15 | f = tempfile.TemporaryFile() | ||
16 | f = tempfile.SpooledTemporaryFile() | ||
| | ||
|
||
SIM115.py:11:5: SIM115 Use context handler for opening files | ||
SIM115.py:15:5: SIM115 Use context handler for opening files | ||
| | ||
9 | f = Path("foo.txt").open() | ||
10 | f = pathlib.Path("foo.txt").open() | ||
11 | f = pl.Path("foo.txt").open() | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ SIM115 | ||
12 | f = P("foo.txt").open() | ||
13 | data = f.read() | ||
13 | f = P("foo.txt").open() | ||
14 | f = tempfile.NamedTemporaryFile() | ||
15 | f = tempfile.TemporaryFile() | ||
| ^^^^^^^^^^^^^^^^^^^^^^ SIM115 | ||
16 | f = tempfile.SpooledTemporaryFile() | ||
17 | data = f.read() | ||
| | ||
|
||
SIM115.py:12:5: SIM115 Use context handler for opening files | ||
SIM115.py:16:5: SIM115 Use context handler for opening files | ||
| | ||
10 | f = pathlib.Path("foo.txt").open() | ||
11 | f = pl.Path("foo.txt").open() | ||
12 | f = P("foo.txt").open() | ||
| ^^^^^^^^^^^^^^^^^ SIM115 | ||
13 | data = f.read() | ||
14 | f.close() | ||
14 | f = tempfile.NamedTemporaryFile() | ||
15 | f = tempfile.TemporaryFile() | ||
16 | f = tempfile.SpooledTemporaryFile() | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SIM115 | ||
17 | data = f.read() | ||
18 | f.close() | ||
| | ||
|
||
SIM115.py:39:9: SIM115 Use context handler for opening files | ||
SIM115.py:43:9: SIM115 Use context handler for opening files | ||
| | ||
37 | # SIM115 | ||
38 | with contextlib.ExitStack(): | ||
39 | f = open("filename") | ||
41 | # SIM115 | ||
42 | with contextlib.ExitStack(): | ||
43 | f = open("filename") | ||
| ^^^^ SIM115 | ||
40 | | ||
41 | # OK | ||
44 | | ||
45 | # OK | ||
| | ||
|
||
|