Skip to content

Method argument errors refer to method's class, not callee's #14896

Open
@ikonst

Description

@ikonst
from typing import NewType
from typing_extensions import Self


class C:
    def foo(self: Self, other: Self) -> int: raise NotImplementedError


D = NewType('D', C)

d = D(C())
d.foo(42)  # E:  Argument 1 to "foo" of "C" has incompatible type "int"; expected "D"

This is pretty minor, but "foo" of "C" here feels misleading. Would it be clearer to name the instance's type?

Playground: https://mypy-play.net/?mypy=latest&python=3.11&gist=9b6fe04dddab8ed91a41c819bff3854a

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions