summaryrefslogtreecommitdiffstats
path: root/yt_dlp/jsinterp.py
diff options
context:
space:
mode:
Diffstat (limited to 'yt_dlp/jsinterp.py')
-rw-r--r--yt_dlp/jsinterp.py24
1 files changed, 12 insertions, 12 deletions
diff --git a/yt_dlp/jsinterp.py b/yt_dlp/jsinterp.py
index bda3fb4..a0f3289 100644
--- a/yt_dlp/jsinterp.py
+++ b/yt_dlp/jsinterp.py
@@ -190,7 +190,7 @@ class Debugger:
cls.write('=> Raises:', e, '<-|', stmt, level=allow_recursion)
raise
if cls.ENABLED and stmt.strip():
- if should_ret or not repr(ret) == stmt:
+ if should_ret or repr(ret) != stmt:
cls.write(['->', '=>'][should_ret], repr(ret), '<-|', stmt, level=allow_recursion)
return ret, should_ret
return interpret_statement
@@ -216,7 +216,7 @@ class JSInterpreter:
self.code, self._functions = code, {}
self._objects = {} if objects is None else objects
- class Exception(ExtractorError):
+ class Exception(ExtractorError): # noqa: A001
def __init__(self, msg, expr=None, *args, **kwargs):
if expr is not None:
msg = f'{msg.rstrip()} in: {truncate_string(expr, 50, 50)}'
@@ -235,7 +235,7 @@ class JSInterpreter:
flags = 0
if not expr:
return flags, expr
- for idx, ch in enumerate(expr):
+ for idx, ch in enumerate(expr): # noqa: B007
if ch not in cls._RE_FLAGS:
break
flags |= cls._RE_FLAGS[ch]
@@ -474,7 +474,7 @@ class JSInterpreter:
if remaining.startswith('{'):
body, expr = self._separate_at_paren(remaining)
else:
- switch_m = re.match(r'switch\s*\(', remaining) # FIXME
+ switch_m = re.match(r'switch\s*\(', remaining) # FIXME: ?
if switch_m:
switch_val, remaining = self._separate_at_paren(remaining[switch_m.end() - 1:])
body, expr = self._separate_at_paren(remaining, '}')
@@ -585,9 +585,9 @@ class JSInterpreter:
return int(expr), should_return
elif expr == 'break':
- raise JS_Break()
+ raise JS_Break
elif expr == 'continue':
- raise JS_Continue()
+ raise JS_Continue
elif expr == 'undefined':
return JS_Undefined, should_return
elif expr == 'NaN':
@@ -667,12 +667,12 @@ class JSInterpreter:
self.interpret_expression(v, local_vars, allow_recursion)
for v in self._separate(arg_str)]
- if obj == str:
+ if obj is str:
if member == 'fromCharCode':
assertion(argvals, 'takes one or more arguments')
return ''.join(map(chr, argvals))
raise self.Exception(f'Unsupported String method {member}', expr)
- elif obj == float:
+ elif obj is float:
if member == 'pow':
assertion(len(argvals) == 2, 'takes two arguments')
return argvals[0] ** argvals[1]
@@ -697,12 +697,12 @@ class JSInterpreter:
elif member == 'splice':
assertion(isinstance(obj, list), 'must be applied on a list')
assertion(argvals, 'takes one or more arguments')
- index, howMany = map(int, (argvals + [len(obj)])[:2])
+ index, how_many = map(int, ([*argvals, len(obj)])[:2])
if index < 0:
index += len(obj)
add_items = argvals[2:]
res = []
- for i in range(index, min(index + howMany, len(obj))):
+ for _ in range(index, min(index + how_many, len(obj))):
res.append(obj.pop(index))
for i, item in enumerate(add_items):
obj.insert(index + i, item)
@@ -726,12 +726,12 @@ class JSInterpreter:
elif member == 'forEach':
assertion(argvals, 'takes one or more arguments')
assertion(len(argvals) <= 2, 'takes at-most 2 arguments')
- f, this = (argvals + [''])[:2]
+ f, this = ([*argvals, ''])[:2]
return [f((item, idx, obj), {'this': this}, allow_recursion) for idx, item in enumerate(obj)]
elif member == 'indexOf':
assertion(argvals, 'takes one or more arguments')
assertion(len(argvals) <= 2, 'takes at-most 2 arguments')
- idx, start = (argvals + [0])[:2]
+ idx, start = ([*argvals, 0])[:2]
try:
return obj.index(idx, start)
except ValueError: