-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Restore dict based typesafe caching #4898
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
Conversation
This also restores isfile_case caching and fixes a type error (!).
Does this need to go into release-0.590? I.e. is it a critical bugfix to the PEP 561 code or just a performance improvement? (I haven't looked yet -- was there a perf regression in situations that don't invoke PEP 561?) |
mypy/stubgen.py
Outdated
@@ -160,7 +160,8 @@ def find_module_path_and_all(module: str, pyversion: Tuple[int, int], | |||
module_all = getattr(mod, '__all__', None) | |||
else: | |||
# Find module by going through search path. | |||
module_path = mypy.build.FindModuleCache().find_module(module, ['.'] + search_path, | |||
module_path = mypy.build.FindModuleCache().find_module(module, | |||
('.',) + tuple(search_path), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gvanrossum this change (just this!) is a bug on master. lib_path
should be a tuple
, and as you can see to the left, it is passed as a list
. I can split this fix out if you don't want the rest. (This could cause issues with lru_cache
).
(The rest is related to file system consistency)
EDIT: added more info.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the concrete effect here? Could this cause problems to users?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Essentially, lru_cache
won't be able to hash the passed list
.
$ python -m mypy.stubgen --no-import mypy
Traceback (most recent call last):
File "C:\Python36\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "C:\Python36\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\ethanhs\Documents\mypy\mypy\stubgen.py", line 1022, in <module>
main()
File "C:\Users\ethanhs\Documents\mypy\mypy\stubgen.py", line 901, in main
raise e
File "C:\Users\ethanhs\Documents\mypy\mypy\stubgen.py", line 898, in main
include_private=options.include_private)
File "C:\Users\ethanhs\Documents\mypy\mypy\stubgen.py", line 106, in generate_stub_for_module
interpreter=interpreter)
File "C:\Users\ethanhs\Documents\mypy\mypy\stubgen.py", line 164, in find_module_path_and_all
interpreter)
TypeError: unhashable type: 'list'
So yes, at least changing the list to a tuple should go into 0.590.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then maybe make a separate PR for that change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, please split that out -- I can cherry-pick a 3-line fix to stubgen with a lot less risk and effort than this whole PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From #4898. This should be cherry-picked into the 0.590 release. Apologies for the last minute bug!
From python#4898. This should be cherry-picked into the 0.590 release. Apologies for the last minute bug!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks for restoring the old caching implementation -- when most of the code can be type checked, gaps in type checking coverage are dangerous as people tend to assume that type checking will catch certain categories of errors.
This also restores
isfile_case
caching and fixes a type error (and legitimate bug) (!).The last remaining follow up from #4693 is to run only one Python subprocess.