Skip to content

Commit 4523b63

Browse files
committed
Make error messages more consistent
1 parent c1b9142 commit 4523b63

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

asyncpg/mypy/hooks.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,13 @@ def record_getitem(ctx: mypy.plugin.MethodContext) \
4747
name = value
4848

4949
if name is None:
50-
ctx.api.fail('Unexpected key "{}" for record "{}'
51-
.format(value, ctx.type.type.name),
50+
is_int = isinstance(value, int)
51+
formatted_key = value if is_int else \
52+
"'{}'".format(value)
53+
ctx.api.fail('Record "{}" has no {} {}'
54+
.format(ctx.type.type.name,
55+
'index' if is_int else 'key',
56+
formatted_key),
5257
ctx.context)
5358
else:
5459
node = ctx.type.type.get(name)
@@ -79,8 +84,8 @@ def record_get(ctx: mypy.plugin.MethodContext) \
7984
name = value
8085

8186
if name is None:
82-
ctx.api.fail('Unexpected key "{}" for record "{}'
83-
.format(value, ctx.type.type.name),
87+
ctx.api.fail('Record "{}" has no key \'{}\''
88+
.format(ctx.type.type.name, value),
8489
ctx.context)
8590
else:
8691
node = ctx.type.type.get(name)

0 commit comments

Comments
 (0)