Fixed #23381 -- Context manager initial state should be determined in __enter__()