mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-01 14:21:24 +00:00
[flake8-simplify
] - extend open-file-with-context-handler to work with dbm.sqlite3 (SIM115
) (#13104)
## Summary Adds upcoming `dbm.sqlite3` to rule that suggests using context managers to open things with. See: https://docs.python.org/3.13/library/dbm.html#module-dbm.sqlite3 ## Test Plan `cargo test`
This commit is contained in:
parent
5af48337a5
commit
0b5828a1e8
3 changed files with 22 additions and 1 deletions
|
@ -243,3 +243,16 @@ def aliased():
|
|||
from tarfile import TarFile as TF
|
||||
f = TF("foo").open()
|
||||
f.close()
|
||||
|
||||
import dbm.sqlite3
|
||||
|
||||
# OK
|
||||
with dbm.sqlite3.open("foo.db") as f:
|
||||
print(f.keys())
|
||||
|
||||
# OK
|
||||
dbm.sqlite3.open("foo.db").close()
|
||||
|
||||
# SIM115
|
||||
f = dbm.sqlite3.open("foo.db")
|
||||
f.close()
|
||||
|
|
|
@ -165,7 +165,7 @@ fn is_open_preview(semantic: &SemanticModel, call: &ast::ExprCall) -> bool {
|
|||
| "tokenize"
|
||||
| "wave",
|
||||
"open"
|
||||
] | ["dbm", "gnu" | "ndbm" | "dumb", "open"]
|
||||
] | ["dbm", "gnu" | "ndbm" | "dumb" | "sqlite3", "open"]
|
||||
| ["fileinput", "FileInput" | "input"]
|
||||
| ["io", "open" | "open_code"]
|
||||
| ["lzma", "LZMAFile" | "open"]
|
||||
|
|
|
@ -324,3 +324,11 @@ SIM115.py:244:9: SIM115 Use a context manager for opening files
|
|||
| ^^^^^^^^^^^^^^ SIM115
|
||||
245 | f.close()
|
||||
|
|
||||
|
||||
SIM115.py:257:5: SIM115 Use a context manager for opening files
|
||||
|
|
||||
256 | # SIM115
|
||||
257 | f = dbm.sqlite3.open("foo.db")
|
||||
| ^^^^^^^^^^^^^^^^ SIM115
|
||||
258 | f.close()
|
||||
|
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue