Skip to content

Commit

Permalink
Merge pull request #3193 from jakestambaugh/master
Browse files Browse the repository at this point in the history
Add support for parsing lists of str in config files if multiple=True
  • Loading branch information
bdarnell committed Oct 15, 2022
2 parents 15d1a72 + e150461 commit 031c435
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion tornado/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,9 @@ def parse_config_file(self, path: str, final: bool = True) -> None:
% (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])
Expand Down
3 changes: 3 additions & 0 deletions tornado/test/options_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ def _define_options(self):
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):
Expand All @@ -216,6 +217,7 @@ def _check_options_values(self, options):
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()
Expand All @@ -230,6 +232,7 @@ def test_types(self):
"--timedelta=45s",
"--email=tornado@web.com",
"--list-of-int=1,2,3",
"--list-of-str=a,b,c",
]
)
self._check_options_values(options)
Expand Down
1 change: 1 addition & 0 deletions tornado/test/options_test_types.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
1 change: 1 addition & 0 deletions tornado/test/options_test_types_str.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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'

0 comments on commit 031c435

Please sign in to comment.