diff --git a/pep-0008.txt b/pep-0008.txt index a01d0e237..421352c4d 100644 --- a/pep-0008.txt +++ b/pep-0008.txt @@ -837,6 +837,20 @@ 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: + + Yes: with auto_commit_or_rollback(conn): + do_transaction(conn) + + No: with conn: + do_transaction(conn) + + The latter example doesn't provide any information to indicate that + the __enter__ and __exit__ methods are doing something other than + closing the connection after a transaction. Being explicit is + important in this case. + - Use string methods instead of the string module. String methods are always much faster and share the same API with