Skip to content

Commit

Permalink
Fix some EncodingWarnings in python 3.10 (PEP 597) (#1614)
Browse files Browse the repository at this point in the history
  • Loading branch information
GalaxySnail committed Oct 7, 2022
1 parent eff8476 commit 7ecc951
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions piptools/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ def __str__(self) -> str:


def read_cache_file(cache_file_path: str) -> CacheDict:
with open(cache_file_path) as cache_file:
with open(cache_file_path, encoding="utf-8") as cache_file:
try:
doc = json.load(cache_file)
except json.JSONDecodeError:
except (json.JSONDecodeError, UnicodeDecodeError):
raise CorruptCacheError(cache_file_path)

# Check version and load the contents
Expand Down Expand Up @@ -108,7 +108,7 @@ def as_cache_key(self, ireq: InstallRequirement) -> CacheKey:
def write_cache(self) -> None:
"""Writes the cache to disk as JSON."""
doc = {"__format__": 1, "dependencies": self._cache}
with open(self._cache_file, "w") as f:
with open(self._cache_file, "w", encoding="utf-8") as f:
json.dump(doc, f, sort_keys=True)

def clear(self) -> None:
Expand Down

0 comments on commit 7ecc951

Please sign in to comment.