Skip to content

Commit

Permalink
style: silence flake8-blind-except warnings
Browse files Browse the repository at this point in the history
BLE001 Do not catch blind exception: `Exception`

The proper exception type when passing an incorrect value to get()
should be KeyError instead of ValueError.
  • Loading branch information
DimitriPapadopoulos committed Jan 13, 2024
1 parent 0d7ae7b commit 6a1cd35
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions yamllint/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def extend(self, base_config):
def parse(self, raw_content):
try:
conf = yaml.safe_load(raw_content)
except Exception as e:
except yaml.YAMLError as e:
raise YamlLintConfigError(f'invalid config: {e}') from e

if not isinstance(conf, dict):
Expand All @@ -94,7 +94,7 @@ def parse(self, raw_content):
base = YamlLintConfig(file=path)
try:
self.extend(base)
except Exception as e:
except AssertionError as e:
raise YamlLintConfigError(f'invalid config: {e}') from e

if 'ignore' in conf and 'ignore-from-file' in conf:
Expand Down Expand Up @@ -142,7 +142,7 @@ def validate(self):
for id in self.rules:
try:
rule = yamllint.rules.get(id)
except Exception as e:
except LookupError as e:
raise YamlLintConfigError(f'invalid config: {e}') from e

self.rules[id] = validate_rule_conf(rule, self.rules[id])
Expand Down
2 changes: 1 addition & 1 deletion yamllint/rules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,6 @@

def get(id):
if id not in _RULES:
raise ValueError(f'no such rule: "{id}"')
raise KeyError(f'no such rule: "{id}"')

return _RULES[id]

0 comments on commit 6a1cd35

Please sign in to comment.