pytype
pytype copied to clipboard
merge-pyi: async def given `coroutine` type, but requires the inner return type?
I ran pytype
and then merge-pyi
on an existing codebase. In a few places, the following was added.
async def _commit(self) -> Coroutine[Any, Any, list]:
...
...
return list()
However, this will result in an error when running pytype, as the expected type is list. This can be resolved with a Union, though this seems off?
async def _commit(self) -> Union[Coroutine[Any, Any, list], list]:
...
...
return list()
PR with this staged: https://github.com/googleapis/python-firestore/pull/134/files#diff-b966babc1b8a5b217e6e2c88fad8c38bR133
Adding a Union doesn't seem right. If the only problem with the list annotation is that it doesn't match what merge-pyi inserted and it otherwise works for type-checking, I'd go with that. If the Coroutine annotation is the right one, you can add # pytype: disable=bad-return-type
on the return list()
line to silence the error. Either way, I agree that this seems like a bug.
@rchen152 yeah. I think these should all be the inner type, not a coroutine type (list in this case)
I was cautious that maybe they can look like both (based on if awaited maybe?) but I think you have the right of it.