Merge pull request #3193 from jakestambaugh/master

Add support for parsing lists of str in config files if multiple=True
This commit is contained in:
Ben Darnell 2022-10-15 11:40:46 -04:00 committed by GitHub
commit 031c435a6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 1 deletions

View File

@ -427,7 +427,9 @@ class OptionParser(object):
% (option.name, option.type.__name__)
)
if type(config[name]) == str and option.type != str:
if type(config[name]) == str and (
option.type != str or option.multiple
):
option.parse(config[name])
else:
option.set(config[name])

View File

@ -204,6 +204,7 @@ class OptionsTest(unittest.TestCase):
options.define("timedelta", type=datetime.timedelta)
options.define("email", type=Email)
options.define("list-of-int", type=int, multiple=True)
options.define("list-of-str", type=str, multiple=True)
return options
def _check_options_values(self, options):
@ -216,6 +217,7 @@ class OptionsTest(unittest.TestCase):
self.assertEqual(options.email.value, "tornado@web.com")
self.assertTrue(isinstance(options.email, Email))
self.assertEqual(options.list_of_int, [1, 2, 3])
self.assertEqual(options.list_of_str, ["a", "b", "c"])
def test_types(self):
options = self._define_options()
@ -230,6 +232,7 @@ class OptionsTest(unittest.TestCase):
"--timedelta=45s",
"--email=tornado@web.com",
"--list-of-int=1,2,3",
"--list-of-str=a,b,c",
]
)
self._check_options_values(options)

View File

@ -9,3 +9,4 @@ datetime = datetime(2013, 4, 28, 5, 16)
timedelta = timedelta(0, 45)
email = Email('tornado@web.com')
list_of_int = [1, 2, 3]
list_of_str = ["a", "b", "c"]

View File

@ -6,3 +6,4 @@ datetime = '2013-04-28 05:16'
timedelta = '45s'
email = 'tornado@web.com'
list_of_int = '1,2,3'
list_of_str = 'a,b,c'