-
Notifications
You must be signed in to change notification settings - Fork 288
Closed
Description
(venv) ➜ pytype --version
2023.07.12
(venv) ➜ python --version
Python 3.10.12
Consider following example:
import abc
import asyncio
from typing import AsyncIterator
class BaseTestClass(abc.ABC):
@abc.abstractmethod
async def count(self) -> AsyncIterator[int]:
raise NotImplementedError()
async def follow(self) -> None:
async for message in self.count():
print(message)
class TestClass(BaseTestClass):
async def count(self) -> AsyncIterator[int]:
for i in range(5):
yield i
if __name__ == '__main__':
asyncio.run(TestClass().follow())
Output of pytype is:
(venv) ➜ pytype minimal_async_iterator.py
Computing dependencies
Analyzing 1 sources with 0 local dependencies
ninja: Entering directory `.pytype'
[1/1] check minimal_async_iterator
FAILED: <dir>/.pytype/pyi/minimal_async_iterator.pyi
<dir>/venv/bin/python3.10 -m pytype.single --imports_info <dir>/.pytype/imports/minimal_async_iterator.imports --module-name minimal_async_iterator --platform darwin -V 3.10 -o <dir>/.pytype/pyi/minimal_async_iterator.pyi --analyze-annotated --nofail --quick <dir>/minimal_async_iterator.py
File "<dir>/minimal_async_iterator.py", line 17, in follow: No attribute '__aiter__' on Coroutine[Any, Any, AsyncIterator[int]] [attribute-error]
File "<dir>/minimal_async_iterator.py", line 21, in TestClass: Overriding method signature mismatch [signature-mismatch]
Base signature: 'def BaseTestClass.count(self) -> Coroutine[Any, Any, AsyncIterator[int]]'.
Subclass signature: 'def TestClass.count(self) -> AsyncIterator[int]'.
Return type mismatch.
For more details, see https://google.github.io/pytype/errors.html
ninja: build stopped: subcommand failed.
Leaving directory '.pytype'
Simply removing the async
keyword from the definition of BaseTestClass.count
makes pytype run successfully. This is unexpected, since now the derived function TestClass.count
does not have the same signature as its base class. Running pylint on the file will now instead fail.
Metadata
Metadata
Assignees
Labels
No labels