From f8217408eeea5531b5f4f353b238dc94de705132 Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Tue, 25 Dec 2018 10:31:05 +0100 Subject: logger: Fix constructor default arguments Default arguments cannot be mutable objects. --- crocoite/logger.py | 6 +++--- crocoite/test_logger.py | 9 +++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) (limited to 'crocoite') diff --git a/crocoite/logger.py b/crocoite/logger.py index 7f4a4de..d882eaf 100644 --- a/crocoite/logger.py +++ b/crocoite/logger.py @@ -43,9 +43,9 @@ class Level(IntEnum): ERROR = 3 class Logger: - def __init__ (self, consumer=[], bindings={}): - self.bindings = bindings - self.consumer = consumer + def __init__ (self, consumer=None, bindings=None): + self.bindings = bindings or {} + self.consumer = consumer or [] def __call__ (self, level, *args, **kwargs): if not isinstance (level, Level): diff --git a/crocoite/test_logger.py b/crocoite/test_logger.py index 3af1321..26e420a 100644 --- a/crocoite/test_logger.py +++ b/crocoite/test_logger.py @@ -80,3 +80,12 @@ def test_datetime (logger): ret = logger.debug() assert 'date' in ret +def test_independence (): + """ Make sure two instances are completely independent """ + l1 = Logger () + c = QueueConsumer () + l1.connect (c) + l2 = Logger () + l2.info (nothing='nothing') + assert not c.data + -- cgit v1.2.3