forked from pool/python-loguru
		
	OBS-URL: https://build.opensuse.org/package/show/devel:languages:python/python-loguru?expand=0&rev=28
		
			
				
	
	
		
			101 lines
		
	
	
		
			3.5 KiB
		
	
	
	
		
			Diff
		
	
	
	
	
	
			
		
		
	
	
			101 lines
		
	
	
		
			3.5 KiB
		
	
	
	
		
			Diff
		
	
	
	
	
	
| From a7a2d72d9e3495ddec9dde2852fa7a932b76d0c4 Mon Sep 17 00:00:00 2001
 | |
| From: Dave Hall <dave@etianen.com>
 | |
| Date: Sun, 11 Feb 2024 23:34:27 +0000
 | |
| Subject: [PATCH 3/5] Fixing `test_pickling` tests for Python 3.13.
 | |
| 
 | |
| The `Handler.lock` is substituted for a `nullcontext`, keeping Python 3.13 happy. A no-op stub for `Handler.release` is added, keeping all other Python versions happy.
 | |
| ---
 | |
|  tests/test_pickling.py | 6 ++++--
 | |
|  1 file changed, 4 insertions(+), 2 deletions(-)
 | |
| 
 | |
| Index: loguru-0.7.2/tests/test_pickling.py
 | |
| ===================================================================
 | |
| --- loguru-0.7.2.orig/tests/test_pickling.py
 | |
| +++ loguru-0.7.2/tests/test_pickling.py
 | |
| @@ -39,11 +39,18 @@ class StreamHandler:
 | |
|          self.stopped = True
 | |
|  
 | |
|  
 | |
| +class MockLock:
 | |
| +    def __enter__(self):
 | |
| +        pass
 | |
| +
 | |
| +    def __exit__(self, *excinfo):
 | |
| +        pass
 | |
| +
 | |
| +
 | |
|  class StandardHandler(logging.Handler):
 | |
|      def __init__(self, level):
 | |
|          super().__init__(level)
 | |
|          self.written = ""
 | |
| -        self.lock = None
 | |
|  
 | |
|      def emit(self, record):
 | |
|          self.written += record.getMessage()
 | |
| @@ -51,8 +58,11 @@ class StandardHandler(logging.Handler):
 | |
|      def acquire(self):
 | |
|          pass
 | |
|  
 | |
| +    def release(self):
 | |
| +        pass
 | |
| +
 | |
|      def createLock(self):  # noqa: N802
 | |
| -        return None
 | |
| +        self.lock = MockLock()
 | |
|  
 | |
|  
 | |
|  def format_function(record):
 | |
| Index: loguru-0.7.2/loguru/_better_exceptions.py
 | |
| ===================================================================
 | |
| --- loguru-0.7.2.orig/loguru/_better_exceptions.py
 | |
| +++ loguru-0.7.2/loguru/_better_exceptions.py
 | |
| @@ -497,7 +497,7 @@ class ExceptionFormatter:
 | |
|              else:
 | |
|                  yield from self._indent(introduction + "\n", group_nesting)
 | |
|  
 | |
| -        frames_lines = traceback.format_list(frames) + exception_only
 | |
| +        frames_lines = self._format_list(frames) + exception_only
 | |
|          if self._colorize or self._backtrace or self._diagnose:
 | |
|              frames_lines = self._format_locations(frames_lines, has_introduction=has_introduction)
 | |
|  
 | |
| @@ -524,5 +524,39 @@ class ExceptionFormatter:
 | |
|              if not is_exception_group(exc) or group_nesting == 10:
 | |
|                  yield from self._indent("-" * 35, group_nesting + 1, prefix="+-")
 | |
|  
 | |
| +    def _format_list(self, frames):
 | |
| +        result = []
 | |
| +        last_file = None
 | |
| +        last_line = None
 | |
| +        last_name = None
 | |
| +        count = 0
 | |
| +        for filename, lineno, name, line in frames:
 | |
| +            if (
 | |
| +                last_file is not None
 | |
| +                and last_file == filename
 | |
| +                and last_line is not None
 | |
| +                and last_line == lineno
 | |
| +                and last_name is not None
 | |
| +                and last_name == name
 | |
| +            ):
 | |
| +                count += 1
 | |
| +            else:
 | |
| +                if count > 3:
 | |
| +                    result.append(f"  [Previous line repeated {count-3} more times]\n")
 | |
| +                last_file = filename
 | |
| +                last_line = lineno
 | |
| +                last_name = name
 | |
| +                count = 0
 | |
| +            if count >= 3:
 | |
| +                continue
 | |
| +            row = []
 | |
| +            row.append('  File "{}", line {}, in {}\n'.format(filename, lineno, name))
 | |
| +            if line:
 | |
| +                row.append("    {}\n".format(line.strip()))
 | |
| +            result.append("".join(row))
 | |
| +        if count > 3:
 | |
| +            result.append(f"  [Previous line repeated {count-3} more times]\n")
 | |
| +        return result
 | |
| +
 | |
|      def format_exception(self, type_, value, tb, *, from_decorator=False):
 | |
|          yield from self._format_exception(value, tb, is_first=True, from_decorator=from_decorator)
 |