From 86b22649aeb59065b6f8f7fa18ba52f158fbfdfb Mon Sep 17 00:00:00 2001 From: crimsonknave Date: Wed, 22 Oct 2025 13:08:43 -0400 Subject: [PATCH 1/3] Don't clean up the logger if it's provided, the providing function will do that --- annotated_logger/__init__.py | 5 ++++- test/test_memory.py | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/annotated_logger/__init__.py b/annotated_logger/__init__.py index ecac8be..e29430b 100644 --- a/annotated_logger/__init__.py +++ b/annotated_logger/__init__.py @@ -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") @@ -791,6 +791,9 @@ def wrap_function(*args: P.args, **kwargs: P.kwargs) -> R: # 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) + # pass return result return wrap_function diff --git a/test/test_memory.py b/test/test_memory.py index 9c09840..0875d34 100644 --- a/test/test_memory.py +++ b/test/test_memory.py @@ -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: @@ -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 From 449a9c3156faea76cb0ea5ac2db9a49d5520e8d5 Mon Sep 17 00:00:00 2001 From: crimsonknave Date: Wed, 22 Oct 2025 13:11:21 -0400 Subject: [PATCH 2/3] Clean up debugging comment --- annotated_logger/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/annotated_logger/__init__.py b/annotated_logger/__init__.py index e29430b..e6104a7 100644 --- a/annotated_logger/__init__.py +++ b/annotated_logger/__init__.py @@ -793,7 +793,6 @@ def wrap_function(*args: P.args, **kwargs: P.kwargs) -> R: logging.root.manager.loggerDict.pop(logger.logger.name, None) if not pre_execution_annotations: logging.root.manager.loggerDict.pop(logger.logger.name, None) - # pass return result return wrap_function From 917df51c0238483c3ac34c8b3e2d31c0f119c42b Mon Sep 17 00:00:00 2001 From: crimsonknave Date: Wed, 22 Oct 2025 13:12:58 -0400 Subject: [PATCH 3/3] Remove the line used to confirm the tests fail when they should --- annotated_logger/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/annotated_logger/__init__.py b/annotated_logger/__init__.py index e6104a7..9daaec7 100644 --- a/annotated_logger/__init__.py +++ b/annotated_logger/__init__.py @@ -790,7 +790,6 @@ 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