Skip to content

Commit 1aee326

Browse files
committed
add shim for nullcontext
1 parent cb1ebcd commit 1aee326

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

mypy/checkexpr.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
"""Expression type checker. This file is conceptually part of TypeChecker."""
22

3+
from mypy.nullcontext import nullcontext
34
from mypy.ordered_dict import OrderedDict
4-
from contextlib import contextmanager, nullcontext
5+
from contextlib import contextmanager
56
import itertools
67
from typing import (
78
Any, cast, Dict, Set, List, Tuple, Callable, Union, Optional, Sequence, Iterator

mypy/nullcontext.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import sys
2+
from contextlib import contextmanager
3+
from typing import Iterator
4+
5+
if sys.version_info < (3, 7):
6+
@contextmanager
7+
def nullcontext() -> Iterator[None]:
8+
yield
9+
else:
10+
from contextlib import nullcontext as nullcontext, contextmanager # noqa: F401

0 commit comments

Comments
 (0)