Make context manager example likelier
This commit is contained in:
parent
e7bef9d9f5
commit
36e5f61f80
11
pep-0008.txt
11
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
|
||||
|
|
Loading…
Reference in New Issue