Skip to content

Commit 337622c

Browse files
committed
ruff format
1 parent 9a46e00 commit 337622c

File tree

17 files changed

+65
-75
lines changed

17 files changed

+65
-75
lines changed

_pydev_runfiles/pydev_runfiles_xml_rpc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def _encode_if_needed(obj):
203203

204204
elif isinstance(obj, bytes):
205205
try:
206-
return xmlrpclib.Binary(obj.decode(sys.stdin.encoding, 'replace').encode("ISO-8859-1", "xmlcharrefreplace"))
206+
return xmlrpclib.Binary(obj.decode(sys.stdin.encoding, "replace").encode("ISO-8859-1", "xmlcharrefreplace"))
207207
except:
208208
return xmlrpclib.Binary(obj) # bytes already
209209

_pydevd_bundle/_debug_adapter/__main__pydevd_gen_debug_adapter_protocol.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,9 @@ def update_class_to_generate_init(class_to_generate):
458458
# Note: added kwargs because some messages are expected to be extended by the user (so, we'll actually
459459
# make all extendable so that we don't have to worry about which ones -- we loose a little on typing,
460460
# but may be better than doing a allow list based on something only pointed out in the documentation).
461-
class_to_generate["init"] = '''def __init__(self%(args)s, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused)
461+
class_to_generate[
462+
"init"
463+
] = '''def __init__(self%(args)s, update_ids_from_dap=False, **kwargs): # noqa (update_ids_from_dap may be unused)
462464
"""
463465
%(docstring)s
464466
"""

_pydevd_bundle/pydevd_code_to_source.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616

1717
class _Stack(object):
18-
1918
def __init__(self):
2019
self._contents = []
2120

@@ -35,7 +34,6 @@ def pop(self):
3534

3635

3736
class _Token(object):
38-
3937
def __init__(self, i_line, instruction=None, tok=_SENTINEL, priority=0, after=None, end_of_line=False):
4038
"""
4139
:param i_line:
@@ -87,7 +85,6 @@ def __repr__(self):
8785

8886

8987
class _Writer(object):
90-
9188
def __init__(self):
9289
self.line_to_contents = {}
9390
self.all_tokens = set()
@@ -114,7 +111,6 @@ def write(self, line, token):
114111

115112

116113
class _BaseHandler(object):
117-
118114
def __init__(self, i_line, instruction, stack, writer, disassembler):
119115
self.i_line = i_line
120116
self.instruction = instruction
@@ -149,13 +145,11 @@ def _register(cls):
149145

150146

151147
class _BasePushHandler(_BaseHandler):
152-
153148
def _handle(self):
154149
self.stack.push(self)
155150

156151

157152
class _BaseLoadHandler(_BasePushHandler):
158-
159153
def _handle(self):
160154
_BasePushHandler._handle(self)
161155
self.tokens = [_Token(self.i_line, self.instruction)]
@@ -503,7 +497,6 @@ def _compose_line_contents(line_contents, previous_line_tokens):
503497

504498

505499
class _PyCodeToSource(object):
506-
507500
def __init__(self, co, memo=None):
508501
if memo is None:
509502
memo = {}
@@ -593,7 +586,7 @@ def disassemble(self):
593586
stream.write("%s\n" % s)
594587

595588
if dedents_found:
596-
indent = indent[:-(4 * dedents_found)]
589+
indent = indent[: -(4 * dedents_found)]
597590
last_line = i_line
598591

599592
return stream.getvalue()

_pydevd_bundle/pydevd_collect_bytecode_info.py

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111

1212
class TryExceptInfo(object):
13-
1413
def __init__(self, try_line, ignore=False):
1514
"""
1615
:param try_line:
@@ -54,7 +53,6 @@ def __str__(self):
5453

5554

5655
class ReturnInfo(object):
57-
5856
def __init__(self, return_line):
5957
self.return_line = return_line
6058

@@ -119,7 +117,6 @@ def collect_return_info(co, use_func_first_line=False):
119117
if sys.version_info[:2] <= (3, 9):
120118

121119
class _TargetInfo(object):
122-
123120
def __init__(self, except_end_instruction, jump_if_not_exc_instruction=None):
124121
self.except_end_instruction = except_end_instruction
125122
self.jump_if_not_exc_instruction = jump_if_not_exc_instruction
@@ -138,7 +135,7 @@ def __str__(self):
138135

139136
def _get_except_target_info(instructions, exception_end_instruction_index, offset_to_instruction_idx):
140137
next_3 = [
141-
j_instruction.opname for j_instruction in instructions[exception_end_instruction_index: exception_end_instruction_index + 3]
138+
j_instruction.opname for j_instruction in instructions[exception_end_instruction_index : exception_end_instruction_index + 3]
142139
]
143140
# print('next_3:', [(j_instruction.opname, j_instruction.argval) for j_instruction in instructions[exception_end_instruction_index:exception_end_instruction_index + 3]])
144141
if next_3 == ["POP_TOP", "POP_TOP", "POP_TOP"]: # try..except without checking exception.
@@ -178,7 +175,7 @@ def _get_except_target_info(instructions, exception_end_instruction_index, offse
178175
return _TargetInfo(except_end_instruction)
179176

180177
elif next_3 and next_3[0] == "DUP_TOP": # try..except AssertionError.
181-
iter_in = instructions[exception_end_instruction_index + 1:]
178+
iter_in = instructions[exception_end_instruction_index + 1 :]
182179
for j, jump_if_not_exc_instruction in enumerate(iter_in):
183180
if jump_if_not_exc_instruction.opname == "JUMP_IF_NOT_EXC_MATCH":
184181
# Python 3.9
@@ -213,7 +210,7 @@ def collect_try_except_info(co, use_func_first_line=False):
213210

214211
try_except_info_lst = []
215212

216-
op_offset_to_line = dict((k, v) for (k, v) in dis.findlinestarts(co) if v is not None)
213+
op_offset_to_line = dict((k, v) for (k, v) in dis.findlinestarts(co) if v is not None)
217214

218215
offset_to_instruction_idx = {}
219216

@@ -262,7 +259,7 @@ def collect_try_except_info(co, use_func_first_line=False):
262259
try_except_info.except_end_line = _get_line(op_offset_to_line, except_end_instruction.offset, firstlineno, search=True)
263260
try_except_info_lst.append(try_except_info)
264261

265-
for raise_instruction in instructions[i: offset_to_instruction_idx[try_except_info.except_end_bytecode_offset]]:
262+
for raise_instruction in instructions[i : offset_to_instruction_idx[try_except_info.except_end_bytecode_offset]]:
266263
if raise_instruction.opname == "RAISE_VARARGS":
267264
if raise_instruction.argval == 0:
268265
try_except_info.raise_lines_in_except.append(
@@ -274,7 +271,6 @@ def collect_try_except_info(co, use_func_first_line=False):
274271
elif sys.version_info[:2] == (3, 10):
275272

276273
class _TargetInfo(object):
277-
278274
def __init__(self, except_end_instruction, jump_if_not_exc_instruction=None):
279275
self.except_end_instruction = except_end_instruction
280276
self.jump_if_not_exc_instruction = jump_if_not_exc_instruction
@@ -293,21 +289,21 @@ def __str__(self):
293289

294290
def _get_except_target_info(instructions, exception_end_instruction_index, offset_to_instruction_idx):
295291
next_3 = [
296-
j_instruction.opname for j_instruction in instructions[exception_end_instruction_index: exception_end_instruction_index + 3]
292+
j_instruction.opname for j_instruction in instructions[exception_end_instruction_index : exception_end_instruction_index + 3]
297293
]
298294
# print('next_3:', [(j_instruction.opname, j_instruction.argval) for j_instruction in instructions[exception_end_instruction_index:exception_end_instruction_index + 3]])
299295
if next_3 == ["POP_TOP", "POP_TOP", "POP_TOP"]: # try..except without checking exception.
300296
# Previously there was a jump which was able to point where the exception would end. This
301297
# is no longer true, now a bare except doesn't really have any indication in the bytecode
302298
# where the end would be expected if the exception wasn't raised, so, we just blindly
303299
# search for a POP_EXCEPT from the current position.
304-
for pop_except_instruction in instructions[exception_end_instruction_index + 3:]:
300+
for pop_except_instruction in instructions[exception_end_instruction_index + 3 :]:
305301
if pop_except_instruction.opname == "POP_EXCEPT":
306302
except_end_instruction = pop_except_instruction
307303
return _TargetInfo(except_end_instruction)
308304

309305
elif next_3 and next_3[0] == "DUP_TOP": # try..except AssertionError.
310-
iter_in = instructions[exception_end_instruction_index + 1:]
306+
iter_in = instructions[exception_end_instruction_index + 1 :]
311307
for jump_if_not_exc_instruction in iter_in:
312308
if jump_if_not_exc_instruction.opname == "JUMP_IF_NOT_EXC_MATCH":
313309
# Python 3.9
@@ -332,7 +328,7 @@ def collect_try_except_info(co, use_func_first_line=False):
332328

333329
try_except_info_lst = []
334330

335-
op_offset_to_line = dict((k, v) for (k, v) in dis.findlinestarts(co) if v is not None)
331+
op_offset_to_line = dict((k, v) for (k, v) in dis.findlinestarts(co) if v is not None)
336332

337333
offset_to_instruction_idx = {}
338334

@@ -386,15 +382,15 @@ def collect_try_except_info(co, use_func_first_line=False):
386382
except_end_line = -1
387383
start_i = offset_to_instruction_idx[try_except_info.except_bytecode_offset]
388384
end_i = offset_to_instruction_idx[except_end_instruction.offset]
389-
for instruction in instructions[start_i: end_i + 1]:
385+
for instruction in instructions[start_i : end_i + 1]:
390386
found_at_line = op_offset_to_line.get(instruction.offset)
391387
if found_at_line is not None and found_at_line > except_end_line:
392388
except_end_line = found_at_line
393389
try_except_info.except_end_line = except_end_line - firstlineno
394390

395391
try_except_info_lst.append(try_except_info)
396392

397-
for raise_instruction in instructions[i: offset_to_instruction_idx[try_except_info.except_end_bytecode_offset]]:
393+
for raise_instruction in instructions[i : offset_to_instruction_idx[try_except_info.except_end_bytecode_offset]]:
398394
if raise_instruction.opname == "RAISE_VARARGS":
399395
if raise_instruction.argval == 0:
400396
try_except_info.raise_lines_in_except.append(
@@ -413,11 +409,11 @@ def collect_try_except_info(co, use_func_first_line=False):
413409
"""
414410
return []
415411

412+
416413
import ast as ast_module
417414

418415

419416
class _Visitor(ast_module.NodeVisitor):
420-
421417
def __init__(self):
422418
self.try_except_infos = []
423419
self._stack = []
@@ -489,7 +485,6 @@ def collect_try_except_info_from_contents(contents, filename="<unknown>"):
489485

490486

491487
class _MsgPart(object):
492-
493488
def __init__(self, line, tok):
494489
assert line >= 0
495490
self.line = line
@@ -528,13 +523,12 @@ def add_to_line_to_contents(cls, obj, line_to_contents, line=None):
528523

529524

530525
class _Disassembler(object):
531-
532526
def __init__(self, co, firstlineno, level=0):
533527
self.co = co
534528
self.firstlineno = firstlineno
535529
self.level = level
536530
self.instructions = list(iter_instructions(co))
537-
op_offset_to_line = self.op_offset_to_line = dict((k, v) for (k, v) in dis.findlinestarts(co) if v is not None)
531+
op_offset_to_line = self.op_offset_to_line = dict((k, v) for (k, v) in dis.findlinestarts(co) if v is not None)
538532

539533
# Update offsets so that all offsets have the line index (and update it based on
540534
# the passed firstlineno).
@@ -671,7 +665,7 @@ def _lookahead(self):
671665
else:
672666
return None # This is odd
673667

674-
del self.instructions[delta: delta + next_instruction.argval + 1] # +1 = BUILD_TUPLE
668+
del self.instructions[delta : delta + next_instruction.argval + 1] # +1 = BUILD_TUPLE
675669

676670
found = iter(found[delta:])
677671

_pydevd_bundle/pydevd_comm.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,6 @@ def process_command(self, cmd_id, seq, text):
328328

329329

330330
class FSNotifyThread(PyDBDaemonThread):
331-
332331
def __init__(self, py_db, api, watch_dirs):
333332
PyDBDaemonThread.__init__(self, py_db)
334333
self.api = api
@@ -577,7 +576,6 @@ def __str__(self):
577576

578577

579578
class InternalThreadCommandForAnyThread(InternalThreadCommand):
580-
581579
def __init__(self, thread_id, method=None, *args, **kwargs):
582580
assert thread_id == "*"
583581

@@ -744,7 +742,6 @@ def internal_smart_step_into(py_db, thread_id, offset, child_offset, set_additio
744742

745743

746744
class InternalSetNextStatementThread(InternalThreadCommand):
747-
748745
def __init__(self, thread_id, cmd_id, line, func_name, seq=0):
749746
"""
750747
cmd_id may actually be one of:
@@ -861,7 +858,6 @@ def do_it(self, dbg):
861858

862859

863860
class InternalGetArray(InternalThreadCommand):
864-
865861
def __init__(self, seq, roffset, coffset, rows, cols, format, thread_id, frame_id, scope, attrs):
866862
self.sequence = seq
867863
self.thread_id = thread_id
@@ -1264,10 +1260,10 @@ def __create_frame():
12641260
safe_repr_custom_attrs = {}
12651261
if context == "clipboard":
12661262
safe_repr_custom_attrs = dict(
1267-
maxstring_outer=2 ** 64,
1268-
maxstring_inner=2 ** 64,
1269-
maxother_outer=2 ** 64,
1270-
maxother_inner=2 ** 64,
1263+
maxstring_outer=2**64,
1264+
maxstring_inner=2**64,
1265+
maxother_outer=2**64,
1266+
maxother_inner=2**64,
12711267
)
12721268

12731269
if context == "repl" and eval_result is None:
@@ -1348,9 +1344,8 @@ def internal_evaluate_expression(dbg, seq, thread_id, frame_id, expression, is_e
13481344

13491345

13501346
def _set_expression_response(py_db, request, error_message):
1351-
body = pydevd_schema.SetExpressionResponseBody(value='')
1352-
variables_response = pydevd_base_schema.build_response(request, kwargs={
1353-
'body':body, 'success':False, 'message': error_message})
1347+
body = pydevd_schema.SetExpressionResponseBody(value="")
1348+
variables_response = pydevd_base_schema.build_response(request, kwargs={"body": body, "success": False, "message": error_message})
13541349
py_db.writer.add_command(NetCommand(CMD_RETURN, 0, variables_response, is_json=True))
13551350

13561351

@@ -1366,18 +1361,18 @@ def internal_set_expression_json(py_db, request, thread_id):
13661361
fmt = fmt.to_dict()
13671362

13681363
frame = py_db.find_frame(thread_id, frame_id)
1369-
exec_code = '%s = (%s)' % (expression, value)
1364+
exec_code = "%s = (%s)" % (expression, value)
13701365
try:
13711366
pydevd_vars.evaluate_expression(py_db, frame, exec_code, is_exec=True)
13721367
except (Exception, KeyboardInterrupt):
1373-
_set_expression_response(py_db, request, error_message='Error executing: %s' % (exec_code,))
1368+
_set_expression_response(py_db, request, error_message="Error executing: %s" % (exec_code,))
13741369
return
13751370

13761371
# Ok, we have the result (could be an error), let's put it into the saved variables.
13771372
frame_tracker = py_db.suspended_frames_manager.get_frame_tracker(thread_id)
13781373
if frame_tracker is None:
13791374
# This is not really expected.
1380-
_set_expression_response(py_db, request, error_message='Thread id: %s is not current thread id.' % (thread_id,))
1375+
_set_expression_response(py_db, request, error_message="Thread id: %s is not current thread id." % (thread_id,))
13811376
return
13821377

13831378
# Now that the exec is done, get the actual value changed to return.

_pydevd_bundle/pydevd_daemon_thread.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def _patch_threading_to_hide_pydevd_threads():
101101
{"_active_limbo_lock", "_limbo", "_active", "values", "list"},
102102
{"_active_limbo_lock", "_limbo", "_active", "values", "NULL + list"},
103103
{"NULL + list", "_active", "_active_limbo_lock", "NULL|self + values", "_limbo"},
104-
{'_active_limbo_lock', 'values + NULL|self', '_limbo', '_active', 'list + NULL'},
104+
{"_active_limbo_lock", "values + NULL|self", "_limbo", "_active", "list + NULL"},
105105
):
106106
pydev_log.debug("Applying patching to hide pydevd threads (Py3 version).")
107107

_pydevd_bundle/pydevd_frame.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
def get_smart_step_into_variant_from_frame_offset(*args, **kwargs):
2626
return None
2727

28+
2829
# IFDEF CYTHON
2930
# cython_inline_constant: CMD_STEP_INTO = 107
3031
# cython_inline_constant: CMD_STEP_INTO_MY_CODE = 144
@@ -123,6 +124,7 @@ class _TryExceptContainerObj(object):
123124

124125
try_except_infos = None
125126

127+
126128
# ENDIF
127129

128130

_pydevd_bundle/pydevd_save_locals.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def update_globals_and_locals(updated_globals, initial_globals, frame):
124124
if key in f_locals:
125125
f_locals[key] = None
126126
except Exception as e:
127-
pydev_log.info('Unable to remove key: %s from locals. Exception: %s', key, e)
127+
pydev_log.info("Unable to remove key: %s from locals. Exception: %s", key, e)
128128

129129
if f_locals is not None:
130130
save_locals(frame)

_pydevd_bundle/pydevd_trace_dispatch_regular.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,7 @@ def fix_top_level_trace_and_get_trace_func(py_db, frame):
187187
if top_level_thread_tracer is None:
188188
# Stop in some internal place to report about unhandled exceptions
189189
top_level_thread_tracer = TopLevelThreadTracerOnlyUnhandledExceptions(args)
190-
additional_info.top_level_thread_tracer_unhandled = (
191-
top_level_thread_tracer
192-
) # Hack for cython to keep it alive while the thread is alive (just the method in the SetTrace is not enough).
190+
additional_info.top_level_thread_tracer_unhandled = top_level_thread_tracer # Hack for cython to keep it alive while the thread is alive (just the method in the SetTrace is not enough).
193191

194192
# print(' --> found to trace unhandled', f_unhandled.f_code.co_name, f_unhandled.f_code.co_filename, f_unhandled.f_code.co_firstlineno)
195193
f_trace = top_level_thread_tracer.get_trace_dispatch_func()

_pydevd_frame_eval/vendored/bytecode/concrete.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ def disassemble(cls, lineno, code, offset):
119119

120120

121121
class ConcreteBytecode(_bytecode._BaseBytecodeList):
122-
123122
def __init__(self, instructions=(), *, consts=(), names=(), varnames=()):
124123
super().__init__()
125124
self.consts = list(consts)
@@ -169,7 +168,7 @@ def __eq__(self, other):
169168

170169
@staticmethod
171170
def from_code(code, *, extended_arg=False):
172-
line_starts = dict((k, v) for (k, v) in dis.findlinestarts(code) if v is not None)
171+
line_starts = dict((k, v) for (k, v) in dis.findlinestarts(code) if v is not None)
173172

174173
# find block starts
175174
instructions = []

0 commit comments

Comments
 (0)