Skip to content

Commit

Permalink
Revert hynek#657
Browse files Browse the repository at this point in the history
The changes introduced in hynek#657 are no longer needed since
_format_exception() is now only called if _figure_out_exc_info() detects
an actual exception
  • Loading branch information
sscherfke committed Dec 1, 2024
1 parent 3644778 commit 42314f6
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 27 deletions.
10 changes: 0 additions & 10 deletions src/structlog/_frames.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,12 @@
from .typing import ExcInfo


def is_missing_exc_info(exc_info: ExcInfo) -> bool:
"""
Return True if exc_info is the missing value.
"""
return exc_info == (None, None, None) # type: ignore[comparison-overlap]


def _format_exception(exc_info: ExcInfo) -> str:
"""
Prettyprint an `exc_info` tuple.
Shamelessly stolen from stdlib's logging module.
"""
if is_missing_exc_info(exc_info):
return "MISSING"

sio = StringIO()

traceback.print_exception(exc_info[0], exc_info[1], exc_info[2], None, sio)
Expand Down
4 changes: 0 additions & 4 deletions src/structlog/tracebacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
from types import ModuleType, TracebackType
from typing import Any, Iterable, Sequence, Tuple, Union

from ._frames import is_missing_exc_info


try:
import rich
Expand Down Expand Up @@ -414,8 +412,6 @@ def __init__(
self.use_rich = use_rich

def __call__(self, exc_info: ExcInfo) -> list[dict[str, Any]]:
if is_missing_exc_info(exc_info):
return []
trace = extract(
*exc_info,
show_locals=self.show_locals,
Expand Down
15 changes: 2 additions & 13 deletions tests/test_tracebacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -734,31 +734,20 @@ def test_json_traceback_value_error(
tracebacks.ExceptionDictTransformer(**kwargs)


def test_exception_dict_transformer_missing_exc_info():
"""
ExceptionDictTransformer returns an empty list if exc_info is missing.
"""
transformer = tracebacks.ExceptionDictTransformer()

result = transformer(exc_info=(None, None, None))

assert [] == result


class TestLogException:
"""
Higher level "integration tests" for "Logger.exception()".
"""

@pytest.fixture()
@pytest.fixture
def cap_logs(self) -> structlog.testing.LogCapture:
"""
Create a LogCapture to be used as processor and fixture for retrieving
logs in tests.
"""
return structlog.testing.LogCapture()

@pytest.fixture()
@pytest.fixture
def logger(
self, cap_logs: structlog.testing.LogCapture
) -> structlog.Logger:
Expand Down

0 comments on commit 42314f6

Please sign in to comment.