Skip to content

Commit

Permalink
Test against Python 3.12 (non-dev) and 3.13 (dev) (#1079)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
etianen authored Feb 17, 2024
1 parent b80d5d1 commit 9311c76
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
12 changes: 11 additions & 1 deletion loguru/_better_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 12 additions & 2 deletions tests/test_pickling.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,30 @@ 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()

def acquire(self):
pass

def release(self):
pass

def createLock(self): # noqa: N802
return None
self.lock = MockLock()


def format_function(record):
Expand Down

0 comments on commit 9311c76

Please sign in to comment.