Fixed #23381 -- Context manager restored state should be determined in __enter__