From 1e0f8d0d5cae9747369720c7224b37dce590df24 Mon Sep 17 00:00:00 2001 From: Kareem Zidane Date: Tue, 22 Jun 2021 19:07:01 -0400 Subject: [PATCH] factor out nullcontext --- check50/__main__.py | 8 +------- check50/_exceptions.py | 3 +-- check50/contextmanagers.py | 7 +++++++ 3 files changed, 9 insertions(+), 9 deletions(-) create mode 100644 check50/contextmanagers.py diff --git a/check50/__main__.py b/check50/__main__.py index f9f2df3..4af642d 100644 --- a/check50/__main__.py +++ b/check50/__main__.py @@ -22,6 +22,7 @@ import termcolor from . import _exceptions, internal, renderer, __version__ +from .contextmanagers import nullcontext from .runner import CheckRunner LOGGER = logging.getLogger("check50") @@ -53,13 +54,6 @@ def format(self, record): return msg if not self.use_color else termcolor.colored(msg, getattr(record, "color", self.COLORS.get(record.levelname))) -@contextlib.contextmanager -def nullcontext(entry_result=None): - """This is just contextlib.nullcontext but that function is only available in 3.7+.""" - yield entry_result - - - _exceptions.ExceptHook.initialize() diff --git a/check50/_exceptions.py b/check50/_exceptions.py index e564eef..b47959a 100644 --- a/check50/_exceptions.py +++ b/check50/_exceptions.py @@ -5,9 +5,8 @@ import lib50 import termcolor -from contextlib import nullcontext - from . import internal, __version__ +from .contextmanagers import nullcontext class Error(Exception): """Exception for internal check50 errors.""" diff --git a/check50/contextmanagers.py b/check50/contextmanagers.py new file mode 100644 index 0000000..bac6d05 --- /dev/null +++ b/check50/contextmanagers.py @@ -0,0 +1,7 @@ +import contextlib + + +@contextlib.contextmanager +def nullcontext(entry_result=None): + """This is just contextlib.nullcontext but that function is only available in 3.7+.""" + yield entry_result