mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2025-10-03 16:51:50 +00:00
[cleanup] Add more ruff rules (#10149)
Authored by: seproDev Reviewed-by: bashonly <88596187+bashonly@users.noreply.github.com> Reviewed-by: Simon Sawicki <contact@grub4k.xyz>
This commit is contained in:
@@ -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':
|
||||
@@ -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:
|
||||
|
Reference in New Issue
Block a user