Assert not None instead of if check

This commit is contained in:
Devesh Kumar Singh 2020-05-21 22:46:56 +05:30
parent ea7a7d26fc
commit 50cbd6a032
2 changed files with 6 additions and 8 deletions

View File

@ -33,9 +33,9 @@ def auto_decode(data):
for line in data.split(b'\n')[:2]:
if line[0:1] == b'#' and ENCODING_RE.search(line):
result = ENCODING_RE.search(line)
if result:
encoding = result.groups()[0].decode('ascii')
return data.decode(encoding)
assert result is not None
encoding = result.groups()[0].decode('ascii')
return data.decode(encoding)
return data.decode(
locale.getpreferredencoding(False) or sys.getdefaultencoding(),
)

View File

@ -205,7 +205,6 @@ def untar_file(filename, location):
)
continue
else:
fp = None
try:
fp = tar.extractfile(member)
except (KeyError, AttributeError) as exc:
@ -217,11 +216,10 @@ def untar_file(filename, location):
)
continue
ensure_dir(os.path.dirname(path))
assert fp is not None
with open(path, 'wb') as destfp:
if fp:
shutil.copyfileobj(fp, destfp)
if fp:
fp.close()
shutil.copyfileobj(fp, destfp)
fp.close()
# Update the timestamp (useful for cython compiled files)
# https://github.com/python/typeshed/issues/2673
tar.utime(member, path) # type: ignore