Skip to content

Commit 16430e9

Browse files
committed
config: Use "mapping" instead of "dict" for user-facing errors
Previously, these errors used the word "dict" because it's the common term in the Python world. But the YAML term is rather "mapping". The present commit fixes this wording. This originates from this discussion [^2]. [^1]: https://yaml.org/spec/1.2.2/#3211-nodes [^2]: #747 (review)
1 parent 79a6b2b commit 16430e9

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

tests/test_cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ def test_run_with_empty_config(self):
270270
cli.run(('-d', '', 'file'))
271271
self.assertEqual(ctx.returncode, -1)
272272
self.assertEqual(ctx.stdout, '')
273-
self.assertRegex(ctx.stderr, r'^invalid config: not a dict')
273+
self.assertRegex(ctx.stderr, r'^invalid config: not a mapping')
274274

275275
def test_run_with_implicit_extends_config(self):
276276
path = os.path.join(self.wd, 'warn.yaml')

tests/test_config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,12 +199,12 @@ class Rule:
199199
def test_invalid_rule(self):
200200
with self.assertRaisesRegex(
201201
config.YamlLintConfigError,
202-
'invalid config: rules should be a dict'):
202+
'invalid config: rules should be a mapping'):
203203
config.YamlLintConfig('rules:\n')
204204
with self.assertRaisesRegex(
205205
config.YamlLintConfigError,
206206
'invalid config: rule "colons": should be either '
207-
'"enable", "disable" or a dict'):
207+
'"enable", "disable" or a mapping'):
208208
config.YamlLintConfig('rules:\n'
209209
' colons: invalid\n')
210210

yamllint/config.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,12 @@ def parse(self, raw_content):
7979
raise YamlLintConfigError(f'invalid config: {e}') from e
8080

8181
if not isinstance(conf, dict):
82-
raise YamlLintConfigError('invalid config: not a dict')
82+
raise YamlLintConfigError('invalid config: not a mapping')
8383

8484
self.rules = conf.get('rules', {})
8585
if not isinstance(self.rules, dict):
86-
raise YamlLintConfigError('invalid config: rules should be a dict')
86+
raise YamlLintConfigError('invalid config: rules should be a '
87+
'mapping')
8788
for rule in self.rules:
8889
if self.rules[rule] == 'enable':
8990
self.rules[rule] = {}
@@ -235,7 +236,7 @@ def validate_rule_conf(rule, conf):
235236
else:
236237
raise YamlLintConfigError(
237238
f'invalid config: rule "{rule.ID}": should be either "enable", '
238-
f'"disable" or a dict')
239+
f'"disable" or a mapping')
239240

240241
return conf
241242

0 commit comments

Comments
 (0)