MCPcopy Index your code
hub / github.com/python/cpython / closing

Class closing

Lib/contextlib.py:342–364  ·  view source on GitHub ↗

Context to automatically close something at the end of a block. Code like this: with closing( .open( )) as f: is equivalent to this: f = .open( ) try: finally: f.close()

Source from the content-addressed store, hash-verified

340
341
342class closing(AbstractContextManager):
343 """Context to automatically close something at the end of a block.
344
345 Code like this:
346
347 with closing(<module>.open(<arguments>)) as f:
348 <block>
349
350 is equivalent to this:
351
352 f = <module>.open(<arguments>)
353 try:
354 <block>
355 finally:
356 f.close()
357
358 """
359 def __init__(self, thing):
360 self.thing = thing
361 def __enter__(self):
362 return self.thing
363 def __exit__(self, *exc_info):
364 self.thing.close()
365
366
367class aclosing(AbstractAsyncContextManager):

Callers 13

listenerMethod · 0.90
_sigint_handlerMethod · 0.90
_connectFunction · 0.90
attachFunction · 0.90
do_testMethod · 0.90
db_contentMethod · 0.90
setUpMethod · 0.90
checkMethod · 0.90
_executeMethod · 0.90
test_instance_docsMethod · 0.85
test_closingMethod · 0.85

Calls

no outgoing calls

Tested by 8

do_testMethod · 0.72
db_contentMethod · 0.72
setUpMethod · 0.72
checkMethod · 0.72
test_instance_docsMethod · 0.68
test_closingMethod · 0.68
test_closing_errorMethod · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…