Skip to content

Commit

Permalink
Raise exception while accessing rules by index (#4068)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Sorin Sbarnea <ssbarnea@redhat.com>
  • Loading branch information
3 people committed Apr 9, 2024
1 parent f8f36fd commit 88c5bd7
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/ansiblelint/rules/__init__.py
Expand Up @@ -455,6 +455,9 @@ def __len__(self) -> int:

def __getitem__(self, item: Any) -> BaseRule:
"""Return a rule from inside the collection based on its id."""
if not isinstance(item, str):
msg = f"Expected str but got {type(item)} when trying to access rule by it's id"
raise RuntimeError(msg)
for rule in self.rules:
if rule.id == item:
return rule
Expand Down

0 comments on commit 88c5bd7

Please sign in to comment.