Fix ResourceWarning

This commit is contained in:
Kovid Goyal 2021-06-28 20:40:10 +05:30
parent 2105940286
commit 331675d413
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -310,7 +310,8 @@ def save_type_stub(text: str, fpath: str) -> None:
fpath += 'i'
preamble = '# Update this file by running: ./test.py mypy\n\n'
try:
existing = open(fpath).read()
with open(fpath) as fs:
existing = fs.read()
except FileNotFoundError:
existing = ''
current = preamble + text