diff options
author | pukkandan <pukkandan.ytdlp@gmail.com> | 2022-04-11 20:40:28 +0530 |
---|---|---|
committer | pukkandan <pukkandan.ytdlp@gmail.com> | 2022-04-12 05:32:51 +0530 |
commit | 86e5f3ed2e6e71eb81ea4c9e26288f16119ffd0c (patch) | |
tree | 12558e4c8f24c1a8d16ccb63e2455b26c301285a /yt_dlp/jsinterp.py | |
parent | f9934b96145af8ac5dfdcbf684827aeaea9912a7 (diff) | |
download | hypervideo-pre-86e5f3ed2e6e71eb81ea4c9e26288f16119ffd0c.tar.lz hypervideo-pre-86e5f3ed2e6e71eb81ea4c9e26288f16119ffd0c.tar.xz hypervideo-pre-86e5f3ed2e6e71eb81ea4c9e26288f16119ffd0c.zip |
[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
Diffstat (limited to 'yt_dlp/jsinterp.py')
-rw-r--r-- | yt_dlp/jsinterp.py | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/yt_dlp/jsinterp.py b/yt_dlp/jsinterp.py index 350b44dd0..3695a282d 100644 --- a/yt_dlp/jsinterp.py +++ b/yt_dlp/jsinterp.py @@ -71,7 +71,7 @@ class LocalNameSpace(MutableMapping): return f'LocalNameSpace{self.stack}' -class JSInterpreter(object): +class JSInterpreter: def __init__(self, code, objects=None): if objects is None: objects = {} @@ -232,7 +232,7 @@ class JSInterpreter(object): for default in (False, True): matched = False for item in items: - case, stmt = [i.strip() for i in self._separate(item, ':', 1)] + case, stmt = (i.strip() for i in self._separate(item, ':', 1)) if default: matched = matched or case == 'default' elif not matched: @@ -268,10 +268,10 @@ class JSInterpreter(object): expr = expr[:start] + json.dumps(ret) + expr[end:] for op, opfunc in _ASSIGN_OPERATORS: - m = re.match(r'''(?x) - (?P<out>%s)(?:\[(?P<index>[^\]]+?)\])? - \s*%s - (?P<expr>.*)$''' % (_NAME_RE, re.escape(op)), expr) + m = re.match(rf'''(?x) + (?P<out>{_NAME_RE})(?:\[(?P<index>[^\]]+?)\])? + \s*{re.escape(op)} + (?P<expr>.*)$''', expr) if not m: continue right_val = self.interpret_expression(m.group('expr'), local_vars, allow_recursion) @@ -451,9 +451,9 @@ class JSInterpreter(object): m = re.match(r'^(?P<func>%s)\((?P<args>[a-zA-Z0-9_$,]*)\)$' % _NAME_RE, expr) if m: fname = m.group('func') - argvals = tuple([ + argvals = tuple( int(v) if v.isdigit() else local_vars[v] - for v in self._separate(m.group('args'))]) + for v in self._separate(m.group('args'))) if fname in local_vars: return local_vars[fname](argvals) elif fname not in self._functions: |