From 07705c0f1d8d794abfbd7717eebb9557bd18fd01 Mon Sep 17 00:00:00 2001 From: Kevin DeJong Date: Wed, 3 Jul 2024 17:33:35 -0700 Subject: [PATCH] Switch type comparison in BaseFn to use is_types_compatible (#3461) --- src/cfnlint/rules/functions/_BaseFn.py | 4 ++-- test/unit/rules/functions/test_length.py | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/cfnlint/rules/functions/_BaseFn.py b/src/cfnlint/rules/functions/_BaseFn.py index cc48f886eb..2e4e118997 100644 --- a/src/cfnlint/rules/functions/_BaseFn.py +++ b/src/cfnlint/rules/functions/_BaseFn.py @@ -8,7 +8,7 @@ from collections import namedtuple from typing import Any, Tuple -from cfnlint.helpers import ToPy, ensure_list +from cfnlint.helpers import ToPy, ensure_list, is_types_compatible from cfnlint.jsonschema import ValidationError, ValidationResult, Validator from cfnlint.rules import CloudFormationLintRule @@ -118,7 +118,7 @@ def validate_fn_output_types( ) -> ValidationResult: tS = self.resolve_type(validator, s) if tS: - if not any(t in self.types for t in tS): + if not is_types_compatible(self.types, tS): reprs = ", ".join(repr(type) for type in tS) yield ValidationError(f"{instance!r} is not of type {reprs}") diff --git a/test/unit/rules/functions/test_length.py b/test/unit/rules/functions/test_length.py index 9f9eb70205..a6b88a4bb0 100644 --- a/test/unit/rules/functions/test_length.py +++ b/test/unit/rules/functions/test_length.py @@ -113,6 +113,13 @@ def context(cfn): {"transforms": Transforms(["AWS::LanguageExtensions"])}, [], ), + ( + "Fn::Length output while a number can be a string", + {"Fn::Length": []}, + {"type": "string"}, + {"transforms": Transforms(["AWS::LanguageExtensions"])}, + [], + ), ], ) def test_validate(name, instance, schema, context_evolve, expected, rule, context, cfn):