From e54b24547da24d4f0e05d15336b819317effbd2d Mon Sep 17 00:00:00 2001
From: Pauli Virtanen <pauli.t.virtanen@jyu.fi>
Date: Wed, 21 Sep 2022 15:26:55 +0300
Subject: [PATCH] usadelndsoc: fix with_log_level

---
 usadelndsoc/__init__.py | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)

diff --git a/usadelndsoc/__init__.py b/usadelndsoc/__init__.py
index 84d4a11..85ea542 100644
--- a/usadelndsoc/__init__.py
+++ b/usadelndsoc/__init__.py
@@ -1,7 +1,6 @@
 # -*- coding:utf-8; eval: (blacken-mode) -*-
 
 import logging
-import contextlib
 
 
 logger = logging.getLogger(__name__)
@@ -36,15 +35,23 @@ def _init_logging():
     logging.config.dictConfig(cfg)
 
 
-@contextlib.contextmanager
 def with_log_level(level):
-    old_level = int(logger.level)
-    logger.setLevel(level)
-    try:
-        yield
-    finally:
-        logger.setLevel(old_level)
+    import functools
+
+    def deco(func):
+        @functools.wraps(func)
+        def wrapper(*a, **kw):
+            old_level = int(logger.level)
+            logger.setLevel(level)
+            try:
+                return func(*a, **kw)
+            finally:
+                logger.setLevel(old_level)
+
+        return wrapper
+
+    return deco
 
 
 _init_logging()
-del _init_logging, logging, contextlib
+del _init_logging, logging
-- 
GitLab