Add NUMBER and LIST<NUMBER> parsing to cloudformation/parsing.py (#3118)

* Add NUMBER and LIST<NUMBER> parsing to cloudformation/parsing.py

* Fix black formatting error in test_stack_parsing.py
This commit is contained in:
Adam Richie-Halford 2020-07-11 00:43:45 -07:00 committed by GitHub
commit 766f527d37
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 1 deletions

View file

@ -560,6 +560,23 @@ class ResourceMap(collections_abc.Mapping):
if value_type == "CommaDelimitedList" or value_type.startswith("List"):
value = value.split(",")
def _parse_number_parameter(num_string):
"""CloudFormation NUMBER types can be an int or float.
Try int first and then fall back to float if that fails
"""
try:
return int(num_string)
except ValueError:
return float(num_string)
if value_type == "List<Number>":
# The if statement directly above already converted
# to a list. Now we convert each element to a number
value = [_parse_number_parameter(v) for v in value]
if value_type == "Number":
value = _parse_number_parameter(value)
if parameter_slot.get("NoEcho"):
self.no_echo_parameter_keys.append(key)