diff --git a/pep-0008.txt b/pep-0008.txt index 421352c4d..d96238e92 100644 --- a/pep-0008.txt +++ b/pep-0008.txt @@ -837,14 +837,15 @@ Programming Recommendations # Will also catch KeyError raised by handle_value() return key_not_found(key) -- Context managers should be in separate classes whenever they do - something other than acquire and release resources. For example: +- Context managers should be invoked through separate functions or methods + whenever they do something other than acquire and release resources. + For example: - Yes: with auto_commit_or_rollback(conn): - do_transaction(conn) + Yes: with conn.begin_transaction(): + do_stuff_in_transaction(conn) No: with conn: - do_transaction(conn) + do_stuff_in_transaction(conn) The latter example doesn't provide any information to indicate that the __enter__ and __exit__ methods are doing something other than