[cleanup] Upgrade syntax

Using https://github.com/asottile/pyupgrade

1. `__future__` imports and `coding: utf-8` were removed
2. Files were rewritten with `pyupgrade --py36-plus --keep-percent-format`
3. f-strings were cherry-picked from `pyupgrade --py36-plus`

Extractors are left untouched (except removing header) to avoid unnecessary merge conflicts
This commit is contained in:
pukkandan 2022-04-11 20:40:28 +05:30
parent f9934b9614
commit 86e5f3ed2e
No known key found for this signature in database
GPG key ID: 7EEE9E1E817D0A39
1009 changed files with 375 additions and 3224 deletions

View file

@ -1,5 +1,3 @@
from __future__ import unicode_literals
import hashlib
import json
import os
@ -111,11 +109,11 @@ def run_update(ydl):
}
def get_bin_info(bin_or_exe, version):
label = version_labels['%s_%s' % (bin_or_exe, version)]
label = version_labels[f'{bin_or_exe}_{version}']
return next((i for i in version_info['assets'] if i['name'] == 'yt-dlp%s' % label), {})
def get_sha256sum(bin_or_exe, version):
filename = 'yt-dlp%s' % version_labels['%s_%s' % (bin_or_exe, version)]
filename = 'yt-dlp%s' % version_labels[f'{bin_or_exe}_{version}']
urlh = next(
(i for i in version_info['assets'] if i['name'] in ('SHA2-256SUMS')),
{}).get('browser_download_url')
@ -136,7 +134,7 @@ def run_update(ydl):
try:
if os.path.exists(filename + '.old'):
os.remove(filename + '.old')
except (IOError, OSError):
except OSError:
return report_unable('remove the old version')
try:
@ -147,13 +145,13 @@ def run_update(ydl):
urlh = ydl._opener.open(url)
newcontent = urlh.read()
urlh.close()
except (IOError, OSError):
except OSError:
return report_network_error('download latest version')
try:
with open(filename + '.new', 'wb') as outf:
outf.write(newcontent)
except (IOError, OSError):
except OSError:
return report_permission_error(f'{filename}.new')
expected_sum = get_sha256sum(variant, arch)
@ -168,11 +166,11 @@ def run_update(ydl):
try:
os.rename(filename, filename + '.old')
except (IOError, OSError):
except OSError:
return report_unable('move current version')
try:
os.rename(filename + '.new', filename)
except (IOError, OSError):
except OSError:
report_unable('overwrite current version')
os.rename(filename + '.old', filename)
return
@ -195,7 +193,7 @@ def run_update(ydl):
urlh = ydl._opener.open(url)
newcontent = urlh.read()
urlh.close()
except (IOError, OSError):
except OSError:
return report_network_error('download the latest version')
expected_sum = get_sha256sum(variant, pack_type)
@ -207,7 +205,7 @@ def run_update(ydl):
try:
with open(filename, 'wb') as outf:
outf.write(newcontent)
except (IOError, OSError):
except OSError:
return report_unable('overwrite current version')
ydl.to_screen('Updated yt-dlp to version %s; Restart yt-dlp to use the new version' % version_id)