Skip to content

Commit f4de7a5

Browse files
author
Guido van Rossum
committed
Make ConditionalTypeBinder a context manager.
Now we can use `with binder: X` instead of `binder.push_frame(); X; binder.pop_frame()`
1 parent 37c57da commit f4de7a5

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

mypy/checker.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Mypy type checker."""
22

33
import itertools
4+
import contextlib
45

56
from typing import (
67
Any, Dict, Set, List, cast, Tuple, TypeVar, Union, Optional, NamedTuple
@@ -295,6 +296,12 @@ def push_loop_frame(self):
295296
def pop_loop_frame(self):
296297
self.loop_frames.pop()
297298

299+
def __enter__(self) -> None:
300+
self.push_frame()
301+
302+
def __exit__(self, *args: Any) -> None:
303+
self.pop_frame()
304+
298305

299306
def meet_frames(*frames: Frame) -> Frame:
300307
answer = Frame()

0 commit comments

Comments
 (0)