-
Notifications
You must be signed in to change notification settings - Fork 8
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
KeyError in res_strict.graph
in Translator when using external library (numpy
)
#159
Comments
I'm not sure why this is happening, but: a) Nagini uses a really old version of mypy, so it's possible that there's a bug in that version that was fixed long ago; b) the NumPy type stubs use a bunch of features Nagini doesn't support yet, so even if this bug did not exist, there would certainly be other issues later. We're just in the process of starting a project whose goal is, among other things, to make Nagini NumPy compatible. So I hope this will work in a couple of months, but until then, you unfortunately won't be able to verify NumPy client code using Nagini. |
Apparently the problem seems that the Nagini tries to follow def check(self, filename: str, base_dir: str = None) -> bool:
...
# Contains file names of imports found so far
relevant_files = [next(iter(res_strict.graph))]
i = 0
while i < len(relevant_files):
name = relevant_files[i]
# The graphs keys only include files processed by mypy, but a files dep_line_map contains _all_ its imports, including those for ignored modules
for dep_name in res_strict.graph[name].dep_line_map:
if dep_name in IGNORED_IMPORTS:
continue
if dep_name not in relevant_files:
# All imports found (including ignored ones) are added to the list and then queried from the dict
relevant_files.append(dep_name)
i += 1
... I've been able to reproduce the exact same error with mypy version 1.0.0, so that behaviour doesn't seem to have changed in recent versions. Just a guess, but I think we could just skip over these "native" modules. No idea if the missing type information would be a problem in itself though. |
May I ask how this project is currently progressing? The third-party library I am verifying uses a lot of |
This may be an issue with
mypy
and not Nagini, but I discovered an issue when attempting to verify the following minimal Numpy program:The following
KeyError
is produced in NaginiNotes
pillow
(because of insufficient type annotations)numpy.core._multiarray_umath
is not a type but rather a module within numpy.My thoughts (as an outsider to your project)
Digging around in your source code, it is evident that
res_strict
is built bymypy
, andname
(the variable causing the KeyError) is produced using each of all elements inrelevant_files
which is directly defined from[next(iter(res_strict.graph))]
. This causes the KeyError to be especially confusing, as these are all supposed to be keys fromres_strict.graph
. Spitballing, it could be related to #37 but honestly it seems like an issue with mypy'sDict
(since that's the type ofres_strict.graph
as you can see here).The text was updated successfully, but these errors were encountered: