2
0
Fork 0

Make WuttaConfig.get_list() return None by default

instead of empty list `[]`
This commit is contained in:
Lance Edgar 2024-04-14 14:59:32 -05:00
parent 16e9811816
commit 24a86ffeb4
3 changed files with 12 additions and 3 deletions

View file

@ -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/) 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). 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 ## [0.1.9] - 2023-11-30
### Changed ### Changed
- Add generic handler base class, tests, docs. - Add generic handler base class, tests, docs.

View file

@ -2,7 +2,7 @@
################################################################################ ################################################################################
# #
# WuttJamaican -- Base package for Wutta Framework # WuttJamaican -- Base package for Wutta Framework
# Copyright © 2023 Lance Edgar # Copyright © 2023-2024 Lance Edgar
# #
# This file is part of Wutta Framework. # 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, Accepts same params as :meth:`get()` but if a value is found,
it will be coerced to list via it will be coerced to list via
:func:`~wuttjamaican.util.parse_list()`. :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) value = self.get(*args, **kwargs)
return parse_list(value) if value is not None:
return parse_list(value)
def get_dict(self, prefix): def get_dict(self, prefix):
""" """

View file

@ -370,7 +370,7 @@ configure_logging = true
def test_get_list(self): def test_get_list(self):
config = conf.WuttaConfig() config = conf.WuttaConfig()
self.assertEqual(config.get_list('foo.bar'), []) self.assertIsNone(config.get_list('foo.bar'))
config.setdefault('foo.bar', 'hello world') config.setdefault('foo.bar', 'hello world')
self.assertEqual(config.get_list('foo.bar'), ['hello', 'world']) self.assertEqual(config.get_list('foo.bar'), ['hello', 'world'])