microsoft / pyright

Static Type Checker for Python
Other
13.5k stars 1.49k forks source link

The presence or absence of Ellipsis determines whether there is an error. #9371

Closed phi-friday closed 3 weeks ago

phi-friday commented 3 weeks ago

no ellipsis

Image

with ellipsis

Image

no ellipsis - logs

❯ uvx pyright src/typed_diskcache/implement/cache/default/main.py
/Users/phi/git/python/repo/typed-diskcache/src/typed_diskcache/implement/cache/default/main.py
  /Users/phi/git/python/repo/typed-diskcache/src/typed_diskcache/implement/cache/default/main.py:11:8 - error: Import "sqlalchemy" could not be resolved (reportMissingImports)
  /Users/phi/git/python/repo/typed-diskcache/src/typed_diskcache/implement/cache/default/main.py:12:6 - error: Import "sqlalchemy" could not be resolved (reportMissingImports)
  /Users/phi/git/python/repo/typed-diskcache/src/typed_diskcache/implement/cache/default/main.py:53:10 - error: Import "sqlalchemy.ext.asyncio" could not be resolved (reportMissingImports)
  /Users/phi/git/python/repo/typed-diskcache/src/typed_diskcache/implement/cache/default/main.py:54:10 - error: Import "sqlalchemy.orm" could not be resolved (reportMissingImports)
  /Users/phi/git/python/repo/typed-diskcache/src/typed_diskcache/implement/cache/default/main.py:179:16 - error: Import "cloudpickle" could not be resolved (reportMissingImports)
  /Users/phi/git/python/repo/typed-diskcache/src/typed_diskcache/implement/cache/default/main.py:191:16 - error: Import "cloudpickle" could not be resolved (reportMissingImports)
  /Users/phi/git/python/repo/typed-diskcache/src/typed_diskcache/implement/cache/default/main.py:567:9 - error: Type of parameter "session" is unknown (reportUnknownParameterType)
  /Users/phi/git/python/repo/typed-diskcache/src/typed_diskcache/implement/cache/default/main.py:624:9 - error: Type of parameter "session" is unknown (reportUnknownParameterType)
  /Users/phi/git/python/repo/typed-diskcache/src/typed_diskcache/implement/cache/default/main.py:1092:15 - error: Method "afilter" overrides class "CacheProtocol" in an incompatible manner
    Return type mismatch: base method returns type "Coroutine[Any, Any, AsyncGenerator[Any, None]]", override returns type "AsyncGenerator[Any, None]"
      "AsyncGenerator[Any, None]" is not assignable to "Coroutine[Any, Any, AsyncGenerator[Any, None]]" (reportIncompatibleMethodOverride)
  /Users/phi/git/python/repo/typed-diskcache/src/typed_diskcache/implement/cache/default/main.py:1941:15 - error: Method "aiterkeys" overrides class "CacheProtocol" in an incompatible manner
    Return type mismatch: base method returns type "Coroutine[Any, Any, AsyncGenerator[Any, None]]", override returns type "AsyncGenerator[Any, None]"
      "AsyncGenerator[Any, None]" is not assignable to "Coroutine[Any, Any, AsyncGenerator[Any, None]]" (reportIncompatibleMethodOverride)
10 errors, 0 warnings, 0 informations 
❯ uvx pyright --version
pyright 1.1.387

with ellipsis - logs

❯ uvx pyright src/typed_diskcache/implement/cache/default/main.py
/Users/phi/git/python/repo/typed-diskcache/src/typed_diskcache/implement/cache/default/main.py
  /Users/phi/git/python/repo/typed-diskcache/src/typed_diskcache/implement/cache/default/main.py:11:8 - error: Import "sqlalchemy" could not be resolved (reportMissingImports)
  /Users/phi/git/python/repo/typed-diskcache/src/typed_diskcache/implement/cache/default/main.py:12:6 - error: Import "sqlalchemy" could not be resolved (reportMissingImports)
  /Users/phi/git/python/repo/typed-diskcache/src/typed_diskcache/implement/cache/default/main.py:53:10 - error: Import "sqlalchemy.ext.asyncio" could not be resolved (reportMissingImports)
  /Users/phi/git/python/repo/typed-diskcache/src/typed_diskcache/implement/cache/default/main.py:54:10 - error: Import "sqlalchemy.orm" could not be resolved (reportMissingImports)
  /Users/phi/git/python/repo/typed-diskcache/src/typed_diskcache/implement/cache/default/main.py:179:16 - error: Import "cloudpickle" could not be resolved (reportMissingImports)
  /Users/phi/git/python/repo/typed-diskcache/src/typed_diskcache/implement/cache/default/main.py:191:16 - error: Import "cloudpickle" could not be resolved (reportMissingImports)
  /Users/phi/git/python/repo/typed-diskcache/src/typed_diskcache/implement/cache/default/main.py:567:9 - error: Type of parameter "session" is unknown (reportUnknownParameterType)
  /Users/phi/git/python/repo/typed-diskcache/src/typed_diskcache/implement/cache/default/main.py:624:9 - error: Type of parameter "session" is unknown (reportUnknownParameterType)
  /Users/phi/git/python/repo/typed-diskcache/src/typed_diskcache/implement/cache/default/main.py:1941:15 - error: Method "aiterkeys" overrides class "CacheProtocol" in an incompatible manner
    Return type mismatch: base method returns type "Coroutine[Any, Any, AsyncGenerator[Any, None]]", override returns type "AsyncGenerator[Any, None]"
      "AsyncGenerator[Any, None]" is not assignable to "Coroutine[Any, Any, AsyncGenerator[Any, None]]" (reportIncompatibleMethodOverride)
9 errors, 0 warnings, 0 informations 

The error that occurs in aiterkeys is for the same reason, Other errors can be ignored.

repro

# pyright: reportReturnType=false
from __future__ import annotations

from typing import TYPE_CHECKING

from typing_extensions import override

if TYPE_CHECKING:
    from collections.abc import AsyncGenerator

class P:
    async def gen(self) -> AsyncGenerator[int, None]:
        """docstring"""

class C(P):
    @override
    async def gen(self) -> AsyncGenerator[int, None]:
        """docstring"""
        yield 1
❯ uvx pyright test.py
/Users/phi/git/python/repo/typed-diskcache/test.py
  /Users/phi/git/python/repo/typed-diskcache/test.py:19:15 - error: Method "gen" overrides class "P" in an incompatible manner
    Return type mismatch: base method returns type "Coroutine[Any, Any, AsyncGenerator[int, None]]", override returns type "AsyncGenerator[int, None]"
      "AsyncGenerator[int, None]" is not assignable to "Coroutine[Any, Any, AsyncGenerator[int, None]]" (reportIncompatibleMethodOverride)
1 error, 0 warnings, 0 informations 
phi-friday commented 3 weeks ago

I thought it was a bug because it only happens for AsyncGenerator, but it happens for mypy as well. Since it doesn't seem to be a bug, we close the issue.