Browse Source

[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
pukkandan 2 years ago
parent
commit
86e5f3ed2e

+ 0 - 1
CONTRIBUTING.md

@@ -178,7 +178,6 @@ After you have ensured this site is distributing its content legally, you can fo
 1. Start with this simple template and save it to `yt_dlp/extractor/yourextractor.py`:
 
     ```python
-    # coding: utf-8
     from .common import InfoExtractor
     
     

+ 1 - 3
devscripts/bash-completion.py

@@ -1,11 +1,9 @@
 #!/usr/bin/env python3
-from __future__ import unicode_literals
-
 import os
 from os.path import dirname as dirn
 import sys
 
-sys.path.insert(0, dirn(dirn((os.path.abspath(__file__)))))
+sys.path.insert(0, dirn(dirn(os.path.abspath(__file__))))
 import yt_dlp
 
 BASH_COMPLETION_FILE = "completions/bash/yt-dlp"

+ 4 - 6
devscripts/check-porn.py

@@ -1,6 +1,4 @@
 #!/usr/bin/env python3
-from __future__ import unicode_literals
-
 """
 This script employs a VERY basic heuristic ('porn' in webpage.lower()) to check
 if we are not 'age_limit' tagging some porn site
@@ -29,7 +27,7 @@ for test in gettestcases():
         try:
             webpage = compat_urllib_request.urlopen(test['url'], timeout=10).read()
         except Exception:
-            print('\nFail: {0}'.format(test['name']))
+            print('\nFail: {}'.format(test['name']))
             continue
 
         webpage = webpage.decode('utf8', 'replace')
@@ -39,7 +37,7 @@ for test in gettestcases():
     elif METHOD == 'LIST':
         domain = compat_urllib_parse_urlparse(test['url']).netloc
         if not domain:
-            print('\nFail: {0}'.format(test['name']))
+            print('\nFail: {}'.format(test['name']))
             continue
         domain = '.'.join(domain.split('.')[-2:])
 
@@ -47,11 +45,11 @@ for test in gettestcases():
 
     if RESULT and ('info_dict' not in test or 'age_limit' not in test['info_dict']
                    or test['info_dict']['age_limit'] != 18):
-        print('\nPotential missing age_limit check: {0}'.format(test['name']))
+        print('\nPotential missing age_limit check: {}'.format(test['name']))
 
     elif not RESULT and ('info_dict' in test and 'age_limit' in test['info_dict']
                          and test['info_dict']['age_limit'] == 18):
-        print('\nPotential false negative: {0}'.format(test['name']))
+        print('\nPotential false negative: {}'.format(test['name']))
 
     else:
         sys.stdout.write('.')

+ 1 - 3
devscripts/fish-completion.py

@@ -1,12 +1,10 @@
 #!/usr/bin/env python3
-from __future__ import unicode_literals
-
 import optparse
 import os
 from os.path import dirname as dirn
 import sys
 
-sys.path.insert(0, dirn(dirn((os.path.abspath(__file__)))))
+sys.path.insert(0, dirn(dirn(os.path.abspath(__file__))))
 import yt_dlp
 from yt_dlp.utils import shell_quote
 

+ 0 - 2
devscripts/generate_aes_testdata.py

@@ -1,6 +1,4 @@
 #!/usr/bin/env python3
-from __future__ import unicode_literals
-
 import codecs
 import subprocess
 

+ 0 - 1
devscripts/lazy_load_template.py

@@ -1,4 +1,3 @@
-# coding: utf-8
 import re
 
 from ..utils import bug_reports_message, write_string

+ 2 - 5
devscripts/make_contributing.py

@@ -1,7 +1,4 @@
 #!/usr/bin/env python3
-from __future__ import unicode_literals
-
-import io
 import optparse
 import re
 
@@ -16,7 +13,7 @@ def main():
 
     infile, outfile = args
 
-    with io.open(infile, encoding='utf-8') as inf:
+    with open(infile, encoding='utf-8') as inf:
         readme = inf.read()
 
     bug_text = re.search(
@@ -26,7 +23,7 @@ def main():
 
     out = bug_text + dev_text
 
-    with io.open(outfile, 'w', encoding='utf-8') as outf:
+    with open(outfile, 'w', encoding='utf-8') as outf:
         outf.write(out)
 
 

+ 3 - 4
devscripts/make_issue_template.py

@@ -1,6 +1,4 @@
 #!/usr/bin/env python3
-from __future__ import unicode_literals
-
 import io
 import optparse
 
@@ -13,7 +11,7 @@ def main():
 
     infile, outfile = args
 
-    with io.open(infile, encoding='utf-8') as inf:
+    with open(infile, encoding='utf-8') as inf:
         issue_template_tmpl = inf.read()
 
     # Get the version from yt_dlp/version.py without importing the package
@@ -22,8 +20,9 @@ def main():
 
     out = issue_template_tmpl % {'version': locals()['__version__']}
 
-    with io.open(outfile, 'w', encoding='utf-8') as outf:
+    with open(outfile, 'w', encoding='utf-8') as outf:
         outf.write(out)
 
+
 if __name__ == '__main__':
     main()

+ 5 - 8
devscripts/make_lazy_extractors.py

@@ -1,13 +1,10 @@
 #!/usr/bin/env python3
-from __future__ import unicode_literals, print_function
-
 from inspect import getsource
-import io
 import os
 from os.path import dirname as dirn
 import sys
 
-sys.path.insert(0, dirn(dirn((os.path.abspath(__file__)))))
+sys.path.insert(0, dirn(dirn(os.path.abspath(__file__))))
 
 lazy_extractors_filename = sys.argv[1] if len(sys.argv) > 1 else 'yt_dlp/extractor/lazy_extractors.py'
 if os.path.exists(lazy_extractors_filename):
@@ -25,7 +22,7 @@ from yt_dlp.extractor.common import InfoExtractor, SearchInfoExtractor
 if os.path.exists(plugins_blocked_dirname):
     os.rename(plugins_blocked_dirname, plugins_dirname)
 
-with open('devscripts/lazy_load_template.py', 'rt') as f:
+with open('devscripts/lazy_load_template.py') as f:
     module_template = f.read()
 
 CLASS_PROPERTIES = ['ie_key', 'working', '_match_valid_url', 'suitable', '_match_id', 'get_temp_id']
@@ -72,7 +69,7 @@ classes = _ALL_CLASSES[:-1]
 ordered_cls = []
 while classes:
     for c in classes[:]:
-        bases = set(c.__bases__) - set((object, InfoExtractor, SearchInfoExtractor))
+        bases = set(c.__bases__) - {object, InfoExtractor, SearchInfoExtractor}
         stop = False
         for b in bases:
             if b not in classes and b not in ordered_cls:
@@ -97,9 +94,9 @@ for ie in ordered_cls:
         names.append(name)
 
 module_contents.append(
-    '\n_ALL_CLASSES = [{0}]'.format(', '.join(names)))
+    '\n_ALL_CLASSES = [{}]'.format(', '.join(names)))
 
 module_src = '\n'.join(module_contents) + '\n'
 
-with io.open(lazy_extractors_filename, 'wt', encoding='utf-8') as f:
+with open(lazy_extractors_filename, 'wt', encoding='utf-8') as f:
     f.write(module_src)

+ 2 - 6
devscripts/make_readme.py

@@ -2,10 +2,6 @@
 
 # yt-dlp --help | make_readme.py
 # This must be run in a console of correct width
-
-from __future__ import unicode_literals
-
-import io
 import sys
 import re
 
@@ -15,7 +11,7 @@ helptext = sys.stdin.read()
 if isinstance(helptext, bytes):
     helptext = helptext.decode('utf-8')
 
-with io.open(README_FILE, encoding='utf-8') as f:
+with open(README_FILE, encoding='utf-8') as f:
     oldreadme = f.read()
 
 header = oldreadme[:oldreadme.index('## General Options:')]
@@ -25,7 +21,7 @@ options = helptext[helptext.index('  General Options:'):]
 options = re.sub(r'(?m)^  (\w.+)$', r'## \1', options)
 options = options + '\n'
 
-with io.open(README_FILE, 'w', encoding='utf-8') as f:
+with open(README_FILE, 'w', encoding='utf-8') as f:
     f.write(header)
     f.write(options)
     f.write(footer)

Some files were not shown because too many files changed in this diff