Skip to content

Commit 38b8c60

Browse files
committed
Fix up Record.get()
1 parent 4523b63 commit 38b8c60

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

asyncpg/mypy/hooks.py

+5-9
Original file line numberDiff line numberDiff line change
@@ -84,20 +84,16 @@ def record_get(ctx: mypy.plugin.MethodContext) \
8484
name = value
8585

8686
if name is None:
87+
if default_arg is not None:
88+
return default_arg
89+
8790
ctx.api.fail('Record "{}" has no key \'{}\''
8891
.format(ctx.type.type.name, value),
8992
ctx.context)
9093
else:
9194
node = ctx.type.type.get(name)
9295

93-
assert node is not None
94-
95-
if node.type is not None:
96-
if default_arg is not None:
97-
return mypy.types.UnionType([node.type, default_arg],
98-
ctx.context.line,
99-
ctx.context.column)
100-
else:
101-
return node.type
96+
if node is not None and node.type is not None:
97+
return node.type
10298

10399
return ctx.default_return_type

asyncpg/protocol/protocol.pyi

+2-2
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,9 @@ _T = TypeVar('_T')
210210

211211
class Record:
212212
@overload
213-
def get(self, key: Any) -> Optional[Any]: ...
213+
def get(self, key: str) -> Optional[Any]: ...
214214
@overload
215-
def get(self, key: Any, default: _T) -> Union[Any, _T]: ...
215+
def get(self, key: str, default: _T) -> Union[Any, _T]: ...
216216
def items(self) -> Iterator[Tuple[str, Any]]: ...
217217
def keys(self) -> Iterator[str]: ...
218218
def values(self) -> Iterator[Any]: ...

0 commit comments

Comments
 (0)