Skip to content

Show relative error location for function aliases #20640

@ilevkivskyi

Description

@ilevkivskyi

This is a follow-up for #20635

Currently we do not serialize .definition of a CallableType and instead set it in fixup.py if the type appears as a type of a function. This is because there is a reference cycle definition <-> type, and handling it "properly" would require some complications similar to e.g. Instance <-> TypeInfo. However, the current logic causes inconsistencies in error reporting in relative locations. For example, this test fails on second run.

[case testCachedUnexpectedKeywordArgumentAlias]
import a
[file a.py]
import b
b.lol2(uhhhh=12) # tweak
[file a.py.2]
import b
b.lol2(uhhhh=12)
[file b.py]
def lol() -> None: pass
lol2 = lol
[out]
tmp/a.py:2: error: Unexpected keyword argument "uhhhh"
tmp/b.py:1: note: Called function defined here
[out2]
tmp/a.py:2: error: Unexpected keyword argument "uhhhh"
tmp/b.py:1: note: Called function defined here

Same problem also affects our partial plugin. We should either handle .definition "properly" (which may be a big change), or just erase it when aliasing CallableTypes (which will make errors potentially less helpful).

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions