Skip to content
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

Restore dict based typesafe caching #4898

Merged
merged 2 commits into from
Apr 13, 2018
Merged

Restore dict based typesafe caching #4898

merged 2 commits into from
Apr 13, 2018

Conversation

ethanhs
Copy link
Collaborator

@ethanhs ethanhs commented Apr 13, 2018

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.

This also restores isfile_case caching and fixes a type error (!).
@ethanhs ethanhs requested a review from JukkaL April 13, 2018 02:36
@gvanrossum
Copy link
Member

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),
Copy link
Collaborator Author

@ethanhs ethanhs Apr 13, 2018

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.

Copy link
Member

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?

Copy link
Collaborator Author

@ethanhs ethanhs Apr 13, 2018

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.

Copy link
Member

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?

Copy link
Member

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gvanrossum pushed a commit that referenced this pull request Apr 13, 2018
From #4898. This should be cherry-picked into the 0.590 release. Apologies for the last minute bug!
gvanrossum pushed a commit to gvanrossum/mypy that referenced this pull request Apr 13, 2018
From python#4898. This should be cherry-picked into the 0.590 release. Apologies for the last minute bug!
Copy link
Collaborator

@JukkaL JukkaL left a 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.

@JukkaL JukkaL merged commit 2db1dd0 into python:master Apr 13, 2018
@ethanhs ethanhs deleted the dictcache branch January 31, 2019 02:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants