Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions annotated_logger/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
# https://test.pypi.org/project/annotated-logger/
# The dev versions in testpypi can then be pulled in to whatever project needed
# the new feature.
VERSION = "1.3.0" # pragma: no mutate
VERSION = "1.3.1" # pragma: no mutate

T = TypeVar("T")
P = ParamSpec("P")
Expand Down Expand Up @@ -790,7 +790,8 @@ def wrap_function(*args: P.args, **kwargs: P.kwargs) -> R:
finally:
# Remove the logger now that we are done with it,
# otherwise they build up and eat memory
logging.root.manager.loggerDict.pop(logger.logger.name, None)
if not pre_execution_annotations:
logging.root.manager.loggerDict.pop(logger.logger.name, None)
return result

return wrap_function
Expand Down
24 changes: 24 additions & 0 deletions test/test_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@

import contextlib
import logging
from typing import TYPE_CHECKING

import pytest

import example.calculator
import example.default

if TYPE_CHECKING:
from annotated_logger import AnnotatedAdapter


class TestMemory:
Expand All @@ -19,3 +24,22 @@ def test_repeated_calls_do_not_accumulate_loggers(self, denominator):

ending_loggers = len(logging.root.manager.loggerDict)
assert starting_loggers == ending_loggers

def test_provided_true_does_not_prune_early(self):
@example.default.annotate_logs(_typing_self=False, _typing_requested=True)
def outer(annotated_logger: AnnotatedAdapter):
name = annotated_logger.name
assert name in logging.root.manager.loggerDict
inner(annotated_logger)
assert name in logging.root.manager.loggerDict
return name

@example.default.annotate_logs(
provided=True, _typing_self=False, _typing_requested=True
)
def inner(annotated_logger: AnnotatedAdapter):
annotated_logger.info("Inside")
return True

name = outer()
assert name not in logging.root.manager.loggerDict
Loading