Skip to content

"<function> defined here" notes omitted when function is loaded from cache #4772

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
msullivan opened this issue Mar 21, 2018 · 2 comments
Open

Comments

@msullivan
Copy link
Collaborator

mypy emits a nice " defined here" note when calling a function with unexpected keywords arguments.

Unfortunately the note is omitted if the module the function is defined in has been loaded from the cache.
This both eliminates a nice message (which we should add more of!) and causes annoying deviations between modes.

The following coarse-grained incremental test fails

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

As well as this fine-grained incremental test:

[case testUnexpectedKeywordArgument]
import a
[file a.py]
import b
[file a.py.2]
import b
b.lol(uhhhh=12)
[file b.py]
def lol() -> None: pass
[out]
==
a.py:2: error: Unexpected keyword argument "uhhhh" for "lol"
b.py:1: note: "lol" defined here
@emmatyping
Copy link
Member

It seems this may be blocking #1412.

@ilevkivskyi
Copy link
Member

I tried to fix this by serializing just the necessary parts for these better error messages (serializing full definition would be too expensive), but here is a problem. If I write the original definition line number to the cache, then it becomes part of public interface (what is called interface hash in build.py). This is problematic, since it would trigger to many other files to recheck. This only affects coarse grained runs, but in any case it seems wrong to make line number a part of public interface. So if we want better error messages, we need to rethink how we determine public interface, so that we can store some extra metadata.

ilevkivskyi added a commit that referenced this issue May 26, 2018
This is useful to give nicer error messages after serialization.

This is a step towards #4772
Unblocks #1412 (much faster pythoneval tests).
@AlexWaygood AlexWaygood added the topic-error-reporting How we report errors label Apr 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants