Use context manager for brevity
Modernize syntax

--HG--
extra : amend_source : eeaee0372ea8d1d39475a722234c03f6a0247722
Fix NameError (is this code ever used?).

--HG--
extra : amend_source : 4361459883522692c4d70715135439819d981d7a
Patch globals in a function. This technique bypasses the linter warnings about the names not being present, and allows for better documentation.
Use context manager

--HG--
extra : amend_source : 5e98bee2918d9eeb073c8c896a849c5f68da6634