diff options
author | Lars-Dominik Braun <lars@6xq.net> | 2018-12-25 10:31:05 +0100 |
---|---|---|
committer | Lars-Dominik Braun <lars@6xq.net> | 2018-12-25 10:31:05 +0100 |
commit | f8217408eeea5531b5f4f353b238dc94de705132 (patch) | |
tree | d7784a5507602cd7fed637b7d724f8c99bbd111d /crocoite | |
parent | 51b97199270c0ae94e61d64b9bdf2b431f55c441 (diff) | |
download | crocoite-f8217408eeea5531b5f4f353b238dc94de705132.tar.gz crocoite-f8217408eeea5531b5f4f353b238dc94de705132.tar.bz2 crocoite-f8217408eeea5531b5f4f353b238dc94de705132.zip |
logger: Fix constructor default arguments
Default arguments cannot be mutable objects.
Diffstat (limited to 'crocoite')
-rw-r--r-- | crocoite/logger.py | 6 | ||||
-rw-r--r-- | crocoite/test_logger.py | 9 |
2 files changed, 12 insertions, 3 deletions
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 + |