Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 3 additions & 1 deletion 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 @@ -791,6 +791,8 @@ 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)
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 @@

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()

Check failure on line 44 in test/test_memory.py

View workflow job for this annotation

GitHub Actions / pytest (macos-latest, 3.13)

TestMemory.test_provided_true_does_not_prune_early AssertionError: assert 'annotated_logger.472f1999-e726-4a6b-8bc5-2c09cc5870ad' in {'annotated_logger': <Logger annotated_logger (DEBUG)>, 'annotated_logger.actions': <Logger annotated_logger.actions (...2ab1b5fd-a07b-4199-aec6-1dce8d472826': <Logger annotated_logger.api.2ab1b5fd-a07b-4199-aec6-1dce8d472826 (DEBUG)>, ...} + where {'annotated_logger': <Logger annotated_logger (DEBUG)>, 'annotated_logger.actions': <Logger annotated_logger.actions (...2ab1b5fd-a07b-4199-aec6-1dce8d472826': <Logger annotated_logger.api.2ab1b5fd-a07b-4199-aec6-1dce8d472826 (DEBUG)>, ...} = <logging.Manager object at 0x105867e00>.loggerDict + where <logging.Manager object at 0x105867e00> = <RootLogger root (WARNING)>.manager + where <RootLogger root (WARNING)> = logging.root

Check failure on line 44 in test/test_memory.py

View workflow job for this annotation

GitHub Actions / pytest (macos-latest, 3.11)

TestMemory.test_provided_true_does_not_prune_early AssertionError: assert 'annotated_logger.b2a3c8ea-edf0-4da5-bf07-041ea892ae68' in {'annotated_logger': <Logger annotated_logger (DEBUG)>, 'annotated_logger.actions': <Logger annotated_logger.actions (...415198ce-1cbe-453e-bb83-1c9c4aeb94b3': <Logger annotated_logger.api.415198ce-1cbe-453e-bb83-1c9c4aeb94b3 (DEBUG)>, ...} + where {'annotated_logger': <Logger annotated_logger (DEBUG)>, 'annotated_logger.actions': <Logger annotated_logger.actions (...415198ce-1cbe-453e-bb83-1c9c4aeb94b3': <Logger annotated_logger.api.415198ce-1cbe-453e-bb83-1c9c4aeb94b3 (DEBUG)>, ...} = <logging.Manager object at 0x103aefe00>.loggerDict + where <logging.Manager object at 0x103aefe00> = <RootLogger root (WARNING)>.manager + where <RootLogger root (WARNING)> = logging.root

Check failure on line 44 in test/test_memory.py

View workflow job for this annotation

GitHub Actions / pytest (macos-latest, 3.10)

TestMemory.test_provided_true_does_not_prune_early AssertionError: assert 'annotated_logger.df99678b-4c2f-4677-9e0f-d37ed59872f6' in {'annotated_logger': <Logger annotated_logger (DEBUG)>, 'annotated_logger.actions': <Logger annotated_logger.actions (...Logger annotated_logger.api (DEBUG)>, 'annotated_logger.calculator': <Logger annotated_logger.calculator (DEBUG)>, ...} + where {'annotated_logger': <Logger annotated_logger (DEBUG)>, 'annotated_logger.actions': <Logger annotated_logger.actions (...Logger annotated_logger.api (DEBUG)>, 'annotated_logger.calculator': <Logger annotated_logger.calculator (DEBUG)>, ...} = <logging.Manager object at 0x103a8be00>.loggerDict + where <logging.Manager object at 0x103a8be00> = <RootLogger root (WARNING)>.manager + where <RootLogger root (WARNING)> = logging.root

Check failure on line 44 in test/test_memory.py

View workflow job for this annotation

GitHub Actions / pytest (macos-latest, 3.12)

TestMemory.test_provided_true_does_not_prune_early AssertionError: assert 'annotated_logger.543b68e8-eef2-4f13-b5f0-474918ea86c2' in {'annotated_logger': <Logger annotated_logger (DEBUG)>, 'annotated_logger.actions': <Logger annotated_logger.actions (...ba244a86-bdd5-4098-ad77-ebdd33ea6134': <Logger annotated_logger.api.ba244a86-bdd5-4098-ad77-ebdd33ea6134 (DEBUG)>, ...} + where {'annotated_logger': <Logger annotated_logger (DEBUG)>, 'annotated_logger.actions': <Logger annotated_logger.actions (...ba244a86-bdd5-4098-ad77-ebdd33ea6134': <Logger annotated_logger.api.ba244a86-bdd5-4098-ad77-ebdd33ea6134 (DEBUG)>, ...} = <logging.Manager object at 0x10168fe00>.loggerDict + where <logging.Manager object at 0x10168fe00> = <RootLogger root (WARNING)>.manager + where <RootLogger root (WARNING)> = logging.root
assert name not in logging.root.manager.loggerDict
Loading