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

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -