Skip to content

False positive on manual overloaded Foo[T].__init__(self, arg) call #20557

@randolf-scholz

Description

@randolf-scholz

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions