-
-
Notifications
You must be signed in to change notification settings - Fork 278
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
Let AstroidManager.clear_cache
act on other caches
#1521
Merged
Pierre-Sassoulas
merged 20 commits into
pylint-dev:main
from
jacobtylerwalls:clear-cache-alternative
May 6, 2022
Merged
Changes from 12 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
35171c4
Proof of concept for extending
jacobtylerwalls 0ea952c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] f70ef40
parent frame, not parent
jacobtylerwalls 0359025
tinker with disables
jacobtylerwalls 0d4c0d3
Add unit test for clear_cache()
jacobtylerwalls 37b1d91
Update test result
jacobtylerwalls 5fd833a
Ensure no behavior change with path caching
jacobtylerwalls c669f8d
try AstroidCacheSetupMixin?
jacobtylerwalls b5034cd
typo in disable
jacobtylerwalls e83701c
get this disable in the right place. why only on CI?
jacobtylerwalls 012f32f
Move imports into clear_cache
jacobtylerwalls 7bbc702
add disable in test
jacobtylerwalls 8ee0632
Clarify reason for late import
jacobtylerwalls 46d8235
fix disable
jacobtylerwalls b8ac347
use tuple
jacobtylerwalls a88b481
better test method name
jacobtylerwalls 4427b71
Merge branch 'main' into clear-cache-alternative
jacobtylerwalls 6f98e30
Avoid late imports
jacobtylerwalls e0797d4
Add coverage
jacobtylerwalls ea74ae4
Fix test isolation issue
jacobtylerwalls File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,8 +22,9 @@ | |
import sys | ||
import sysconfig | ||
import types | ||
from functools import lru_cache | ||
from pathlib import Path | ||
from typing import Dict, Set | ||
from typing import Set | ||
|
||
from astroid.const import IS_JYTHON, IS_PYPY | ||
from astroid.interpreter._import import spec, util | ||
|
@@ -138,21 +139,19 @@ def _handle_blacklist(blacklist, dirnames, filenames): | |
filenames.remove(norecurs) | ||
|
||
|
||
_NORM_PATH_CACHE: Dict[str, str] = {} | ||
@lru_cache() | ||
def _cache_normalize_path_(path: str) -> str: | ||
jacobtylerwalls marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return _normalize_path(path) | ||
|
||
|
||
def _cache_normalize_path(path: str) -> str: | ||
jacobtylerwalls marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"""Normalize path with caching.""" | ||
# _module_file calls abspath on every path in sys.path every time it's | ||
# called; on a larger codebase this easily adds up to half a second just | ||
# assembling path components. This cache alleviates that. | ||
try: | ||
return _NORM_PATH_CACHE[path] | ||
except KeyError: | ||
if not path: # don't cache result for '' | ||
return _normalize_path(path) | ||
result = _NORM_PATH_CACHE[path] = _normalize_path(path) | ||
return result | ||
if not path: # don't cache result for '' | ||
return _normalize_path(path) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line is not covered, on the other hand are we really ever having something falsey here ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added coverage. We talked a bit about it here. |
||
return _cache_normalize_path_(path) | ||
|
||
|
||
def load_module_from_name(dotted_name: str) -> types.ModuleType: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I was wondering if we could remove the dependency to wrapt following this change, Turns out that there are other uses elsewhere but not that much.