From 24a86ffeb4b693d0d215a390428e1aa448d00d00 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Sun, 14 Apr 2024 14:59:32 -0500 Subject: [PATCH] Make `WuttaConfig.get_list()` return `None` by default instead of empty list `[]` --- CHANGELOG.md | 5 +++++ src/wuttjamaican/conf.py | 8 ++++++-- tests/test_conf.py | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 585387d..7e3b940 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ All notable changes to WuttJamaican will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## Unreleased +### Changed +- `WuttaConfig.get_list()` now returns `None` (instead of `[]`) by + default if there is no config value present. + ## [0.1.9] - 2023-11-30 ### Changed - Add generic handler base class, tests, docs. diff --git a/src/wuttjamaican/conf.py b/src/wuttjamaican/conf.py index 1e2b7eb..f67874b 100644 --- a/src/wuttjamaican/conf.py +++ b/src/wuttjamaican/conf.py @@ -2,7 +2,7 @@ ################################################################################ # # WuttJamaican -- Base package for Wutta Framework -# Copyright © 2023 Lance Edgar +# Copyright © 2023-2024 Lance Edgar # # This file is part of Wutta Framework. # @@ -480,9 +480,13 @@ class WuttaConfig: Accepts same params as :meth:`get()` but if a value is found, it will be coerced to list via :func:`~wuttjamaican.util.parse_list()`. + + :returns: If a value is found, a list is returned. If no + value, returns ``None``. """ value = self.get(*args, **kwargs) - return parse_list(value) + if value is not None: + return parse_list(value) def get_dict(self, prefix): """ diff --git a/tests/test_conf.py b/tests/test_conf.py index 7e9b5cb..c237377 100644 --- a/tests/test_conf.py +++ b/tests/test_conf.py @@ -370,7 +370,7 @@ configure_logging = true def test_get_list(self): config = conf.WuttaConfig() - self.assertEqual(config.get_list('foo.bar'), []) + self.assertIsNone(config.get_list('foo.bar')) config.setdefault('foo.bar', 'hello world') self.assertEqual(config.get_list('foo.bar'), ['hello', 'world'])