Skip to content

Commit 8dae604

Browse files
authored
Change some files to match the rest of the project (#3310)
* Change some files to match the rest of the project * Cleanup some of the typing we do to keep it consistent
1 parent 9d770a2 commit 8dae604

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+398
-364
lines changed

docs/rules.md

+3-6
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,9 @@ The following **208** rules are applied by this linter:
5050

5151
| Rule ID | Title | Description | Config<br />(Name:Type:Default) | Source | Tags |
5252
| -------- | ----- | ----------- | ---------- | ------ | ---- |
53-
| [E0000<a name="E0000"></a>](../src/cfnlint/rules/ParseError.py) | Parsing error found when parsing the template | Checks for JSON/YAML formatting errors in your template | | [Source](https://github.com/aws-cloudformation/cfn-python-lint) | `base` |
54-
| [E0001<a name="E0001"></a>](../src/cfnlint/rules/TransformError.py) | Error found when transforming the template | Errors found when performing transformation on the template | | [Source](https://github.com/aws-cloudformation/cfn-python-lint) | `base`,`transform` |
55-
| [E0002<a name="E0002"></a>](../src/cfnlint/rules/RuleError.py) | Error processing rule on the template | Errors found when processing a rule on the template | | [Source](https://github.com/aws-cloudformation/cfn-python-lint) | `base`,`rule` |
56-
| [E0000<a name="E0000"></a>](../src/cfnlint/rules/ParseError.py) | Parsing error found when parsing the template | Checks for JSON/YAML formatting errors in your template | | [Source](https://github.com/aws-cloudformation/cfn-python-lint) | `base` |
57-
| [E0001<a name="E0001"></a>](../src/cfnlint/rules/TransformError.py) | Error found when transforming the template | Errors found when performing transformation on the template | | [Source](https://github.com/aws-cloudformation/cfn-python-lint) | `base`,`transform` |
58-
| [E0002<a name="E0002"></a>](../src/cfnlint/rules/RuleError.py) | Error processing rule on the template | Errors found when processing a rule on the template | | [Source](https://github.com/aws-cloudformation/cfn-python-lint) | `base`,`rule` |
53+
| [E0000<a name="E0000"></a>](../src/cfnlint/rules/errors/parse.py) | Parsing error found when parsing the template | Checks for JSON/YAML formatting errors in your template | | [Source](https://github.com/aws-cloudformation/cfn-python-lint) | `base` |
54+
| [E0001<a name="E0001"></a>](../src/cfnlint/rules/errors/transform.py) | Error found when transforming the template | Errors found when performing transformation on the template | | [Source](https://github.com/aws-cloudformation/cfn-python-lint) | `base`,`transform` |
55+
| [E0002<a name="E0002"></a>](../src/cfnlint/rules/errors/rule.py) | Error processing rule on the template | Errors found when processing a rule on the template | | [Source](https://github.com/aws-cloudformation/cfn-python-lint) | `base`,`rule` |
5956
| [E1001<a name="E1001"></a>](../src/cfnlint/rules/jsonschema/JsonSchema.py) | Basic CloudFormation Template Configuration | Making sure the basic CloudFormation template components are properly configured | sections:string: | [Source](https://github.com/aws-cloudformation/cfn-python-lint) | `base` |
6057
| [E1002<a name="E1002"></a>](../src/cfnlint/rules/templates/LimitSize.py) | Validate if a template size is too large | Check the size of the template is less than the upper limit | | [Source](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cloudformation-limits.html) | `limits` |
6158
| [E1003<a name="E1003"></a>](../src/cfnlint/rules/templates/LimitDescription.py) | Validate the max size of a description | Check if the size of the template description is less than the upper limit | | [Source](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cloudformation-limits.html) | `description`,`limits` |

src/cfnlint/_typing.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,14 @@
33
SPDX-License-Identifier: MIT-0
44
"""
55

6-
from __future__ import annotations
7-
86
from typing import TYPE_CHECKING, Any, List, Protocol, Union
97

108
if TYPE_CHECKING:
11-
from cfnlint.rules._Rule import RuleMatch
9+
from cfnlint.rules import RuleMatch
1210

1311
RuleMatches = List["RuleMatch"]
1412
Path = List[Union[str, int]]
1513

1614

1715
class CheckValueFn(Protocol):
18-
def __call__(self, value: Any, path: Path, **kwargs: Any) -> list[RuleMatch]: ...
16+
def __call__(self, value: Any, path: Path, **kwargs: Any) -> List["RuleMatch"]: ...

src/cfnlint/api.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
def lint(
2020
s: str,
2121
rules: RulesCollection | None = None,
22-
regions: List[str] | None = None,
22+
regions: list[str] | None = None,
2323
config: ManualArgs | None = None,
24-
) -> List[Match]:
24+
) -> list[Match]:
2525
"""Validate a string template using the specified rules and regions.
2626
2727
Parameters
@@ -30,7 +30,7 @@ def lint(
3030
the template string
3131
rules : RulesCollection
3232
The rules to run against s
33-
regions : List[str]
33+
regions : list[str]
3434
The regions to test against s
3535
3636
Returns
@@ -64,7 +64,7 @@ def lint(
6464
return list(runner.validate_template(None, template))
6565

6666

67-
def lint_all(s: str) -> List[Match]:
67+
def lint_all(s: str) -> list[Match]:
6868
"""Validate a string template against all regions and rules.
6969
7070
Parameters

src/cfnlint/conditions/_condition.py

+32-32
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
SPDX-License-Identifier: MIT-0
44
"""
55

6-
from typing import Any, Dict, List, Mapping, Optional, Sequence, Union
6+
from __future__ import annotations
7+
8+
from typing import Any, Dict, Mapping, Sequence, Union
79

810
from sympy import And, Not, Or, Symbol
911
from sympy.logic.boolalg import BooleanFunction
@@ -19,13 +21,13 @@ class Condition:
1921
"""The generic class to represent any type of Condition"""
2022

2123
def __init__(self) -> None:
22-
self._fn_equals: Optional[Equal] = None
23-
self._condition: Optional[Union[ConditionList, ConditionNamed]] = None
24+
self._fn_equals: Equal | None = None
25+
self._condition: ConditionList | ConditionNamed | None = None
2426

2527
def _init_condition(
2628
self,
2729
condition: _CONDITION,
28-
all_conditions: Dict[str, dict],
30+
all_conditions: dict[str, dict],
2931
) -> None:
3032
if len(condition) == 1:
3133
for k, v in condition.items():
@@ -50,13 +52,13 @@ def _init_condition(
5052
raise ValueError("Condition value must be an object of length 1")
5153

5254
@property
53-
def equals(self) -> List[Equal]:
55+
def equals(self) -> list[Equal]:
5456
"""Returns a Sequence of the Equals that make up the Condition
5557
5658
Args: None
5759
5860
Returns:
59-
Union[Sequence[EqualParameter], Sequence[Equal]]:
61+
Sequence[EqualParameter] | Sequence[Equal] | None:
6062
The Equal that are part of the condition
6163
"""
6264
if self._fn_equals:
@@ -65,13 +67,11 @@ def equals(self) -> List[Equal]:
6567
return self._condition.equals
6668
return []
6769

68-
def build_cnf(
69-
self, params: Dict[str, Symbol]
70-
) -> Optional[Union[BooleanFunction, Symbol]]:
70+
def build_cnf(self, params: dict[str, Symbol]) -> BooleanFunction | Symbol | None:
7171
"""Build a SymPy CNF based on the provided params
7272
7373
Args:
74-
params Dict[str, Symbol]: params is a dict that represents
74+
params dict[str, Symbol]: params is a dict that represents
7575
the hash of an Equal and the SymPy Symbols
7676
7777
Returns:
@@ -98,24 +98,24 @@ class ConditionList(Condition):
9898
"""
9999

100100
def __init__(
101-
self, conditions: Sequence[_CONDITION], all_conditions: Dict[str, dict]
101+
self, conditions: Sequence[_CONDITION], all_conditions: dict[str, dict]
102102
) -> None:
103103
super().__init__()
104-
self._conditions: List[ConditionUnnammed] = []
104+
self._conditions: list[ConditionUnnammed] = []
105105
self._prefix_path: str = ""
106106
for condition in conditions:
107107
self._conditions.append(ConditionUnnammed(condition, all_conditions))
108108

109109
@property
110-
def equals(self) -> List[Equal]:
110+
def equals(self) -> list[Equal]:
111111
"""Returns a List of the Equals that make up the Condition
112112
113113
Args: None
114114
115115
Returns:
116-
List[Equal]: The Equal that are part of the condition
116+
list[Equal]: The Equal that are part of the condition
117117
"""
118-
equals: List[Equal] = []
118+
equals: list[Equal] = []
119119
for condition in self._conditions:
120120
equals.extend(condition.equals)
121121
return equals
@@ -125,20 +125,20 @@ class ConditionAnd(ConditionList):
125125
"""Represents the logic specific to an And Condition"""
126126

127127
def __init__(
128-
self, conditions: Sequence[_CONDITION], all_conditions: Dict[str, dict]
128+
self, conditions: Sequence[_CONDITION], all_conditions: dict[str, dict]
129129
) -> None:
130130
super().__init__(conditions, all_conditions)
131131
self._prefix_path = "Fn::And"
132132

133-
def build_cnf(self, params: Dict[str, Symbol]) -> BooleanFunction:
133+
def build_cnf(self, params: dict[str, Symbol]) -> BooleanFunction:
134134
"""Build a SymPy CNF solver based on the provided params
135135
Args:
136-
params Dict[str, Symbol]: params is a dict that represents
136+
params dict[str, Symbol]: params is a dict that represents
137137
the hash of an Equal and the SymPy Symbols
138138
Returns:
139139
BooleanFunction: An And SymPy BooleanFunction
140140
"""
141-
conditions: List[Any] = []
141+
conditions: list[Any] = []
142142
for child in self._conditions:
143143
conditions.append(child.build_cnf(params))
144144

@@ -153,17 +153,17 @@ class ConditionNot(ConditionList):
153153
"""Represents the logic specific to an Not Condition"""
154154

155155
def __init__(
156-
self, conditions: Sequence[_CONDITION], all_conditions: Dict[str, dict]
156+
self, conditions: Sequence[_CONDITION], all_conditions: dict[str, dict]
157157
) -> None:
158158
super().__init__(conditions, all_conditions)
159159
self._prefix_path = "Fn::Not"
160160
if len(conditions) != 1:
161161
raise ValueError("Condition length must be 1")
162162

163-
def build_cnf(self, params: Dict[str, Symbol]) -> BooleanFunction:
163+
def build_cnf(self, params: dict[str, Symbol]) -> BooleanFunction:
164164
"""Build a SymPy CNF solver based on the provided params
165165
Args:
166-
params Dict[str, Symbol]: params is a dict that represents
166+
params dict[str, Symbol]: params is a dict that represents
167167
the hash of an Equal and the SymPy Symbol
168168
Returns:
169169
BooleanFunction: A Not SymPy BooleanFunction
@@ -179,20 +179,20 @@ class ConditionOr(ConditionList):
179179
"""Represents the logic specific to an Or Condition"""
180180

181181
def __init__(
182-
self, conditions: Sequence[_CONDITION], all_conditions: Dict[str, dict]
182+
self, conditions: Sequence[_CONDITION], all_conditions: dict[str, dict]
183183
) -> None:
184184
super().__init__(conditions, all_conditions)
185185
self._prefix_path = "Fn::Or"
186186

187-
def build_cnf(self, params: Dict[str, Symbol]) -> BooleanFunction:
187+
def build_cnf(self, params: dict[str, Symbol]) -> BooleanFunction:
188188
"""Build a SymPy CNF solver based on the provided params
189189
Args:
190-
params Dict[str, Symbol]: params is a dict that represents
190+
params dict[str, Symbol]: params is a dict that represents
191191
the hash of an Equal and the SymPy Symbols
192192
Returns:
193193
BooleanFunction: An Or SymPy BooleanFunction
194194
"""
195-
conditions: List[Any] = []
195+
conditions: list[Any] = []
196196
for child in self._conditions:
197197
conditions.append(child.build_cnf(params))
198198
return Or(*conditions)
@@ -205,7 +205,7 @@ def _test(self, scenarios: Mapping[str, str]) -> bool:
205205
class ConditionUnnammed(Condition):
206206
"""Represents an unnamed condition which is basically a nested Equals"""
207207

208-
def __init__(self, condition: Any, all_conditions: Dict[str, dict]) -> None:
208+
def __init__(self, condition: Any, all_conditions: dict[str, dict]) -> None:
209209
super().__init__()
210210
if isinstance(condition, dict):
211211
self._init_condition(condition, all_conditions)
@@ -216,7 +216,7 @@ def __init__(self, condition: Any, all_conditions: Dict[str, dict]) -> None:
216216
class ConditionNamed(Condition):
217217
"""The parent condition that directly represents a named condition in a template"""
218218

219-
def __init__(self, name: str, all_conditions: Dict[str, dict]) -> None:
219+
def __init__(self, name: str, all_conditions: dict[str, dict]) -> None:
220220
super().__init__()
221221
condition = all_conditions.get(name)
222222
if isinstance(condition, dict):
@@ -225,20 +225,20 @@ def __init__(self, name: str, all_conditions: Dict[str, dict]) -> None:
225225
else:
226226
raise ValueError(f"Condition {name} must have a value that is an object")
227227

228-
def build_true_cnf(self, params: Dict[str, Symbol]) -> Any:
228+
def build_true_cnf(self, params: dict[str, Symbol]) -> Any:
229229
"""Build a SymPy CNF for a True based scenario
230230
Args:
231-
params Dict[str, Symbol]: params is a dict that represents
231+
params dict[str, Symbol]: params is a dict that represents
232232
the hash of an Equal and the SymPy Symbols
233233
Returns:
234234
Any: A SymPy CNF clause
235235
"""
236236
return self.build_cnf(params)
237237

238-
def build_false_cnf(self, params: Dict[str, Symbol]) -> Any:
238+
def build_false_cnf(self, params: dict[str, Symbol]) -> Any:
239239
"""Build a SymPy CNF for a False based scenario
240240
Args:
241-
params Dict[str, Symbol]: params is a dict that represents
241+
params dict[str, Symbol]: params is a dict that represents
242242
the hash of an Equal and the SymPy CNF Symbols
243243
Returns:
244244
Any: A Not SymPy CNF clause

src/cfnlint/conditions/_equals.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
SPDX-License-Identifier: MIT-0
44
"""
55

6+
from __future__ import annotations
7+
68
import json
79
import logging
8-
from typing import Any, Dict, List, Mapping, Tuple, Union
10+
from typing import Any, Mapping, Tuple
911

1012
from cfnlint.conditions._utils import get_hash
1113

@@ -28,12 +30,12 @@ def __eq__(self, __o: Any):
2830

2931
class Equal:
3032
hash: str
31-
_left: Union[EqualParameter, str]
32-
_right: Union[EqualParameter, str]
33-
_is_static: Union[bool, None]
33+
_left: EqualParameter | str
34+
_right: EqualParameter | str
35+
_is_static: bool | None
3436
_is_region: Tuple[bool, str]
3537

36-
def __init__(self, equal: List[Union[str, dict]]) -> None:
38+
def __init__(self, equal: list[str | dict]) -> None:
3739
self._is_static = None
3840
if isinstance(equal, list) and len(equal) == 2:
3941
# sort to keep consistancy from random ordering
@@ -63,34 +65,32 @@ def __init__(self, equal: List[Union[str, dict]]) -> None:
6365
return
6466
raise ValueError("Equals has to be a list of two values")
6567

66-
def _init_parameter(
67-
self, parameter: Union[Dict, str]
68-
) -> Union[EqualParameter, str]:
68+
def _init_parameter(self, parameter: dict[str, Any] | str) -> EqualParameter | str:
6969
if isinstance(parameter, dict):
7070
return EqualParameter(parameter)
7171
return str(parameter)
7272

7373
@property
74-
def is_static(self) -> Union[bool, None]:
74+
def is_static(self) -> bool | None:
7575
"""Returns a boolean value if the result is always True or False or None if
7676
it isn't a static boolean
7777
7878
Args: None
7979
8080
Returns:
81-
Union[bool, None]: None if the equals can be True or False or True/False if
81+
bool | None: None if the equals can be True or False or True/False if
8282
the equals will always return the same result
8383
"""
8484
return self._is_static
8585

8686
@property
87-
def parameters(self) -> List[EqualParameter]:
87+
def parameters(self) -> list[EqualParameter]:
8888
"""Returns a List of the EqualParameter that make up the Condition
8989
9090
Args: None
9191
9292
Returns:
93-
List[Equal]: A list of the left and right equal parameters if they are
93+
list[Equal]: A list of the left and right equal parameters if they are
9494
of type EqualParameter
9595
"""
9696
params = []

0 commit comments

Comments
 (0)