def METHOD_NAME(self, flags):
    ## bits that we'll set to 1
    turn_on_bits = ~self.flags & flags
    self.flags = self.flags | flags
    try:
        yield
    finally:
        # turn off only the bits we turned on so that something like
        # __future__ that set flags stays.
        self.flags &= ~turn_on_bits