[config] coerce more to string when 'type: str' (#72172)
Change: - When a plugin defines `type: str` on a parameter, treat more kinds of input as a string instead of whatever it is parsed as. Test Plan: - New unit tests - CI Signed-off-by: Rick Elrod <rick@elrod.me>
This commit is contained in:
parent
6e7a40dd94
commit
3b40c6f3b7
4 changed files with 15 additions and 1 deletions
2
changelogs/fragments/more-types-to-string-config.yml
Normal file
2
changelogs/fragments/more-types-to-string-config.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
minor_changes:
|
||||
- "config - more types are now automatically coerced to string when ``type: str`` is used and the value is parsed as a different type"
|
|
@ -149,7 +149,7 @@ def ensure_type(value, value_type, origin=None):
|
|||
errmsg = 'dictionary'
|
||||
|
||||
elif value_type in ('str', 'string'):
|
||||
if isinstance(value, (string_types, AnsibleVaultEncryptedUnicode)):
|
||||
if isinstance(value, (string_types, AnsibleVaultEncryptedUnicode, bool, int, float, complex)):
|
||||
value = unquote(to_text(value, errors='surrogate_or_strict'))
|
||||
else:
|
||||
errmsg = 'string'
|
||||
|
|
0
test/units/config/__init__.py
Normal file
0
test/units/config/__init__.py
Normal file
|
@ -60,6 +60,18 @@ ensure_test_data = [
|
|||
('a', 'string', string_types),
|
||||
('Café', 'string', string_types),
|
||||
('', 'string', string_types),
|
||||
('29', 'str', string_types),
|
||||
('13.37', 'str', string_types),
|
||||
('123j', 'string', string_types),
|
||||
('0x123', 'string', string_types),
|
||||
('true', 'string', string_types),
|
||||
('True', 'string', string_types),
|
||||
(0, 'str', string_types),
|
||||
(29, 'str', string_types),
|
||||
(13.37, 'str', string_types),
|
||||
(123j, 'string', string_types),
|
||||
(0x123, 'string', string_types),
|
||||
(True, 'string', string_types),
|
||||
('None', 'none', type(None))
|
||||
]
|
||||
|
||||
|
|
Loading…
Reference in a new issue