bpo-45975: Simplify some while-loops with walrus operator (GH-29347)

This commit is contained in:
Nick Drozd 2022-11-26 16:33:25 -06:00 committed by GitHub
parent 25bc115df9
commit 024ac542d7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
28 changed files with 41 additions and 153 deletions

View file

@ -265,10 +265,7 @@ def urlretrieve(url, filename=None, reporthook=None, data=None):
if reporthook:
reporthook(blocknum, bs, size)
while True:
block = fp.read(bs)
if not block:
break
while block := fp.read(bs):
read += len(block)
tfp.write(block)
blocknum += 1
@ -1847,10 +1844,7 @@ class URLopener:
size = int(headers["Content-Length"])
if reporthook:
reporthook(blocknum, bs, size)
while 1:
block = fp.read(bs)
if not block:
break
while block := fp.read(bs):
read += len(block)
tfp.write(block)
blocknum += 1