From 9311c763bb3528f87c3c5a13a25ec7387f2cc545 Mon Sep 17 00:00:00 2001 From: Dave Hall Date: Sat, 17 Feb 2024 11:14:22 +0000 Subject: [PATCH] Test against Python 3.12 (non-dev) and 3.13 (dev) (#1079) * Testing against Python 3.12 (non-dev) and Python 3.13 (dev) * Marking `3.13-dev` tests as failable * 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. * Fixing `test_pickling` tests for Python 3.13. The `Handler.lock` is substituted for a `MockLock`, keeping Python 3.13 happy. A no-op stub for `Handler.release` is added, keeping all other Python versions happy. --- .github/workflows/tests.yml | 4 +++- loguru/_better_exceptions.py | 12 +++++++++++- setup.py | 1 + tests/test_pickling.py | 14 ++++++++++++-- 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e9f4cd07..3e235be8 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -9,6 +9,7 @@ on: jobs: tests: if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository + continue-on-error: ${{ endsWith(matrix.python-version, '-dev') }} strategy: fail-fast: false matrix: @@ -20,7 +21,8 @@ jobs: - '3.9' - '3.10' - '3.11' - - 3.12-dev + - '3.12' + - 3.13-dev - pypy-3.9 include: - os: ubuntu-20.04 diff --git a/loguru/_better_exceptions.py b/loguru/_better_exceptions.py index e751cf6e..94610c71 100644 --- a/loguru/_better_exceptions.py +++ b/loguru/_better_exceptions.py @@ -498,7 +498,7 @@ def _format_exception( 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) @@ -526,5 +526,15 @@ def _format_exception( 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 = [] + for filename, lineno, name, line in frames: + row = [] + row.append(' File "{}", line {}, in {}\n'.format(filename, lineno, name)) + if line: + row.append(" {}\n".format(line.strip())) + result.append("".join(row)) + 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) diff --git a/setup.py b/setup.py index 421a39a8..b9fc77ce 100644 --- a/setup.py +++ b/setup.py @@ -47,6 +47,7 @@ "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", "Programming Language :: Python :: 3 :: Only", "Programming Language :: Python :: Implementation :: PyPy", "Programming Language :: Python :: Implementation :: CPython", diff --git a/tests/test_pickling.py b/tests/test_pickling.py index 35ba8883..575ce12e 100644 --- a/tests/test_pickling.py +++ b/tests/test_pickling.py @@ -50,11 +50,18 @@ def _stop(self): 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() @@ -62,8 +69,11 @@ def emit(self, record): def acquire(self): pass + def release(self): + pass + def createLock(self): # noqa: N802 - return None + self.lock = MockLock() def format_function(record):