Skip to content

Commit

Permalink
Make ConditionalTypeBinder a context manager.
Browse files Browse the repository at this point in the history
Now we can use `with binder: X` instead of `binder.push_frame(); X; binder.pop_frame()`
  • Loading branch information
Guido van Rossum committed Apr 19, 2016
1 parent 49e3864 commit 9b7b383
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions mypy/checker.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Mypy type checker."""

import itertools
import contextlib

from typing import (
Any, Dict, Set, List, cast, Tuple, TypeVar, Union, Optional, NamedTuple
Expand Down Expand Up @@ -295,6 +296,12 @@ def push_loop_frame(self):
def pop_loop_frame(self):
self.loop_frames.pop()

def __enter__(self) -> None:
self.push_frame()

def __exit__(self, *args: Any) -> None:
self.pop_frame()


def meet_frames(*frames: Frame) -> Frame:
answer = Frame()
Expand Down

0 comments on commit 9b7b383

Please sign in to comment.