8000 Always write the cache (unless cache_dir is /dev/null) by gvanrossum · Pull Request #3133 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Always write the cache (unless cache_dir is /dev/null) #3133

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

Merged
merged 6 commits into from
Apr 19, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Respond to review; move get_stat(path) up and be more robust
  • Loading branch information
Guido van Rossum committed Apr 5, 2017
commit 3f4706cfee494bb212fb83a32ede2ab3b41e5463
21 changes: 14 additions & 7 deletions mypy/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,20 @@ def write_cache(id: str, path: str, tree: MypyFile,
data_str = json.dumps(data, sort_keys=True)
interface_hash = compute_hash(data_str)

# Obtain and set up metadata
try:
st = manager.get_stat(path)
except OSError as err:
manager.log("Cannot get stat for {}: %s".format(path, err))
Copy link
Member

Choose a reason for hiding this comment

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

Something is wrong with formatting here, this does not fail, but %s is never replaced (at least in Python 3.4 I just tried).

Copy link
Member Author

Choose a reason for hiding this comment

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

Good eye, I am still not in the habit of using {} for format()...

# Remove apparently-invalid cache files.
for filename in [data_json, meta_json]:
try:
os.remove(filename)
except OSError:
pass
# Still return the interface hash we computed.
return interface_hash

# Write data cache file, if applicable
if old_interface_hash == interface_hash:
# If the interface is unchanged, the cached data is guaranteed
Expand All @@ -890,13 +904,6 @@ def write_cache(id: str, path: str, tree: MypyFile,
os.replace(data_json_tmp, data_json)
manager.trace("Interface for {} has changed".format(id))
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't the replace in :890 be only done if there's no OSError in :895?


# Obtain and set up metadata
try:
st = manager.get_stat(path)
except OSError:
manager.log("Cannot write {}".format(path))
return interface_hash

mtime = st.st_mtime
size = st.st_size
options = manager.options.clone_for_module(id)
Expand Down
0