-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Allow multiple shadow files to be specified #5023
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
Changes from 6 commits
42d4a6f
d69b68d
62b79a2
28ca852
003545a
605a37d
34677a9
0ec018b
73752d7
3af2ed6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -655,13 +655,36 @@ def __init__(self, data_dir: str, | |
self.fscache = fscache | ||
self.find_module_cache = FindModuleCache(self.fscache) | ||
|
||
# a mapping from source files to their corresponding shadow files | ||
# for efficient lookup | ||
self.shadow_map = {} # type: Dict[str, str] | ||
if self.options.shadow_file is not None: | ||
self.shadow_map = {source_file: shadow_file | ||
for (source_file, shadow_file) | ||
in self.options.shadow_file} | ||
# a mapping from each file being typechecked to its possible shadow file | ||
self.shadow_equivalence_map = {} # type: Dict[str, Optional[str]] | ||
|
||
def use_fine_grained_cache(self) -> bool: | ||
return self.cache_enabled and self.options.use_fine_grained_cache | ||
|
||
def maybe_swap_for_shadow_path(self, path: str) -> str: | ||
if (self.options.shadow_file and | ||
os.path.samefile(self.options.shadow_file[0], path)): | ||
path = self.options.shadow_file[1] | ||
if not self.options.shadow_file: | ||
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. IMO it would be better if this checked for |
||
return path | ||
|
||
previously_checked = path in self.shadow_equivalence_map | ||
if not previously_checked: | ||
for k in self.shadow_map.keys(): | ||
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'd switch this to (Also perhaps use more imaginative names than |
||
if self.fscache.samefile(path, k): | ||
self.shadow_equivalence_map[path] = self.shadow_map.get(k) | ||
break | ||
else: | ||
self.shadow_equivalence_map[path] = None | ||
|
||
shadow_file = self.shadow_equivalence_map.get(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 and the rest of the function could be shortened to
|
||
if shadow_file: | ||
path = shadow_file | ||
|
||
return path | ||
|
||
def get_stat(self, path: str) -> os.stat_result: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -149,6 +149,11 @@ def md5(self, path: str) -> str: | |
self.read(path) | ||
return self.hash_cache[path] | ||
|
||
def samefile(self, f1: str, f2: str) -> bool: | ||
s1 = self.stat(f1) | ||
s2 = self.stat(f2) | ||
return os.path.samestat(s1, s2) # type: ignore | ||
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'm curious -- why do you need 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. We were missing this function in the stub. We just merged the PR adding it, so this ignore can be removed as soon as we sync typeshed. |
||
|
||
|
||
def copy_os_error(e: OSError) -> OSError: | ||
new = OSError(*e.args) | ||
|
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.
This needs an example -- do you write
--shadow-file X1 X2 Y1 Y2
or--shadow-file X1 X2 --shadow-file Y1 Y2
? (I presume the latter, but some options use the former syntax, and argparse supports both.)Also, this argument has caused many people to be confused. We should present an example explaining that
--shadow-file X1 X2
means that whenever the checker is asked to checkX1
, it actually reads and checks the contents ofX2
, but diagnostics will refer toX1
(it may well be the latter bit that trips people up).