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

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -