-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add documentation and code examples for
consider-using-with
(#6009)
- Loading branch information
Showing
4 changed files
with
13 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
file = open("foo.txt", "r", encoding="utf8") # [consider-using-with] | ||
contents = file.read() | ||
file.close() |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
This message applies to callables of Python's stdlib which can be replaced by a ``with`` statement. | ||
It is suppressed in the following cases: | ||
|
||
- the call is located inside a context manager | ||
- the call result is returned from the enclosing function | ||
- the call result is used in a ``with`` statement itself |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
with open("foo.txt", "r", encoding="utf8") as file: | ||
contents = file.read() |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
- `PEP 343 <https://peps.python.org/pep-0343/>`_ | ||
- `Context managers in Python <https://johnlekberg.com/blog/2020-10-11-ctx-manage.html>`_ by John Lekberg |