Naming for Python context manager that ensures balanced push/pop calls to a stack? -
for api's use stack , push/pop, mismatch in calls push/pop cause serious problems (crashing if we're wrapping c api example).
in case context manager may used, errors in script don't result in invalid state.
for example, this:
item = stack.push() item.do_stuff() # if raises exception, bad things may happen! stack.pop()
could written as:
with stack.push_pop_context() item: item.do_stuff()
to ensure push & pop run.
is there convention naming kind of function? - push_pop_context
Comments
Post a Comment