-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Open
Labels
Description
https://mypy-play.net/?mypy=latest&python=3.12&gist=8fb7e4ecda19d973ed94ee4487bc3ff9
from collections.abc import Sequence, Iterable
from typing import Never, overload
class Foo: ...
class Bar(Foo): ...
class FooSequence[F: Foo](Foo, Sequence[F]):
@overload
def __init__(self: "FooSequence[Never]", /) -> None: ...
@overload
def __init__(self, modules: Iterable[F], /) -> None: ...
def __init__(self, modules: Iterable[F] = (), /) -> None: ...
class BarSequence[B: Bar](Bar, FooSequence[B]):
def __init__(self, modules: Iterable[B] = (), /) -> None:
FooSequence[B].__init__(self, modules) # ❌️main.py:17: error: Argument 1 to "__init__" of "FooSequence" has incompatible type "BarSequence[B]"; expected "FooSequence[Never]" [arg-type]
main.py:17: error: Argument 2 to "__init__" of "FooSequence" has incompatible type "Iterable[B]"; expected "Iterable[Never]" [arg-type]
This looks like a false positive to me; if the overloads are removed, it type checks without error: https://mypy-play.net/?mypy=latest&python=3.12&gist=ac42aa23c117ba5e2f2ea815a23cb134