From 86e5f3ed2e6e71eb81ea4c9e26288f16119ffd0c Mon Sep 17 00:00:00 2001 From: pukkandan Date: Mon, 11 Apr 2022 20:40:28 +0530 Subject: [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 --- yt_dlp/jsinterp.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'yt_dlp/jsinterp.py') 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%s)(?:\[(?P[^\]]+?)\])? - \s*%s - (?P.*)$''' % (_NAME_RE, re.escape(op)), expr) + m = re.match(rf'''(?x) + (?P{_NAME_RE})(?:\[(?P[^\]]+?)\])? + \s*{re.escape(op)} + (?P.*)$''', 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%s)\((?P[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: -- cgit v1.2.3