Skip to content

Incorrect note references builtins.pyi instead of the class definition #20911

@chriselion

Description

@chriselion

Bug Report

When reporting a "Unexpected keyword argument" error for an initializer, the note can incorrectly reference builtins.pyi instead of the class definition.

To Reproduce
https://mypy-play.net/?gist=b50a11afee5d039fb382667dee8b529f

class Foo:
    bar: str
    
def f() -> Foo:
    foo = Foo(bar="bar")
    return foo

f()

For context, I was using pydantic, but forgot to make the class in question inherit from pydantic.BaseModel. But this isn't specific to pydantic.

Expected Behavior

The note should include the class definition, not an incorrect link to builtins.pyi.
This was misleading because I thought my class was shadowing a built-in one, so I tried renaming it.

Actual Behavior

main.py:5: error: Unexpected keyword argument "bar" for "Foo"  [call-arg]
/layers/google.python.pip/pip/lib/python3.12/site-packages/mypy/typeshed/stdlib/builtins.pyi:117: note: "Foo" defined here

I believe the line referenced here is for object.__init__().

Your Environment

  • Mypy version used: 1.19.1
  • Mypy command-line flags: n/a
  • Mypy configuration options from mypy.ini (and other config files): n/a (default for mypy playground)
  • Python version used: python3.12

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions