Skip to content

Commit 206970a

Browse files
Copilotdobairoland
authored andcommitted
refactor: set up and apply pyupgrade ruff rules
Closes #1115 Closes #1116
1 parent 6bc84f2 commit 206970a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+279
-298
lines changed

ci/patch_dev_release.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def patch_file(path, new_version):
1313
assert ".dev" in new_version
1414
new_version = new_version.lstrip("v")
1515

16-
with open(path, "r") as fin:
16+
with open(path) as fin:
1717
lines = fin.readlines()
1818

1919
for i, line in enumerate(lines, start=0):

docs/en/conf.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
#
32
# English Language RTD & Sphinx config file
43
#

esp_rfc2217_server/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def main():
134134
except KeyboardInterrupt:
135135
print(flush=True)
136136
break
137-
except socket.error as msg:
137+
except OSError as msg:
138138
logging.error(str(msg))
139139

140140
logging.info("--- exit ---")

esp_rfc2217_server/esp_port_manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class EspPortManager(serial.rfc2217.PortManager):
3838
def __init__(self, serial_port, connection, esp32r0_delay, logger=None):
3939
self.esp32r0_delay = esp32r0_delay
4040
self.is_download_mode = False
41-
super(EspPortManager, self).__init__(serial_port, connection, logger)
41+
super().__init__(serial_port, connection, logger)
4242

4343
def _telnet_process_subnegotiation(self, suboption):
4444
if suboption[0:1] == COM_PORT_OPTION and suboption[1:2] == SET_CONTROL:
@@ -66,7 +66,7 @@ def _telnet_process_subnegotiation(self, suboption):
6666
]:
6767
return
6868
# only in cases not handled above do the original implementation in PortManager
69-
super(EspPortManager, self)._telnet_process_subnegotiation(suboption)
69+
super()._telnet_process_subnegotiation(suboption)
7070

7171
def _hard_reset_thread(self):
7272
"""

esp_rfc2217_server/redirector.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@
55
import threading
66
import time
77
import logging
8-
import socket
98

109
from esp_rfc2217_server.esp_port_manager import EspPortManager
1110

1211

13-
class Redirector(object):
12+
class Redirector:
1413
def __init__(self, serial_instance, socket, debug=False, esp32r0delay=False):
1514
self.serial = serial_instance
1615
self.socket = socket
@@ -54,7 +53,7 @@ def reader(self):
5453
if data:
5554
# escape outgoing data when needed (Telnet IAC (0xff) character)
5655
self.write(b"".join(self.rfc2217.escape(data)))
57-
except socket.error as msg:
56+
except OSError as msg:
5857
self.log.error("{}".format(msg))
5958
# probably got disconnected
6059
break
@@ -74,7 +73,7 @@ def writer(self):
7473
if not data:
7574
break
7675
self.serial.write(b"".join(self.rfc2217.filter(data)))
77-
except socket.error as msg:
76+
except OSError as msg:
7877
self.log.error("{}".format(msg))
7978
# probably got disconnected
8079
break

espefuse/efuse/base_fields.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from . import util
1818

1919

20-
class CheckArgValue(object):
20+
class CheckArgValue:
2121
def __init__(self, efuses, name):
2222
self.efuses = efuses
2323
self.name = name
@@ -85,7 +85,7 @@ def check_arg_value(efuse, new_value):
8585
return check_arg_value(efuse, new_value)
8686

8787

88-
class EfuseProtectBase(object):
88+
class EfuseProtectBase:
8989
# This class is used by EfuseBlockBase and EfuseFieldBase
9090
read_disable_bit: int | list[int] | None
9191
write_disable_bit: int | list[int] | None
@@ -214,9 +214,7 @@ def get_block_len(self):
214214
elif coding_scheme == self.parent.REGS.CODING_SCHEME_RS:
215215
return self.len * 4
216216
else:
217-
raise esptool.FatalError(
218-
"Coding scheme (%d) not supported" % (coding_scheme)
219-
)
217+
raise esptool.FatalError(f"Coding scheme ({coding_scheme}) not supported")
220218

221219
def get_coding_scheme(self):
222220
if self.id == 0:
@@ -255,7 +253,7 @@ def read(self, print_info=True):
255253
words = self.get_words()
256254
data = BitArray()
257255
for word in reversed(words):
258-
data.append("uint:32=%d" % word)
256+
data.append(f"uint:32={word}")
259257
self.bitarray.overwrite(data, pos=0)
260258
if print_info:
261259
self.print_block(self.bitarray, "read_regs")
@@ -264,13 +262,13 @@ def print_block(self, bit_string, comment, debug=False):
264262
if self.parent.debug or debug:
265263
bit_string.pos = 0
266264
log.print(
267-
"%-15s (%-16s) [%-2d] %s:"
268-
% (self.name, " ".join(self.alias)[:16], self.id, comment),
265+
f"{self.name:<15s} ({' '.join(self.alias)[:16]:<16s}) "
266+
f"[{self.id:<2d}] {comment}:",
269267
" ".join(
270268
[
271-
"%08x" % word
269+
f"{word:08x}"
272270
for word in bit_string.readlist(
273-
"%d*uint:32" % (bit_string.len / 32)
271+
f"{int(bit_string.len / 32)}*uint:32"
274272
)[::-1]
275273
]
276274
),
@@ -285,8 +283,8 @@ def check_wr_data(self):
285283
return False
286284
if len(wr_data.bytes) != len(self.bitarray.bytes):
287285
raise esptool.FatalError(
288-
"Data does not fit: the block%d size is %d bytes, data is %d bytes"
289-
% (self.id, len(self.bitarray.bytes), len(wr_data.bytes))
286+
f"Data does not fit: block{self.id} size "
287+
f"{len(self.bitarray.bytes)} bytes, data {len(wr_data.bytes)} bytes"
290288
)
291289
self.check_wr_rd_protect()
292290

@@ -468,7 +466,7 @@ def burn(self):
468466
self.wr_bitarray.set(0)
469467

470468

471-
class EspEfusesBase(object):
469+
class EspEfusesBase:
472470
"""
473471
Wrapper object to manage the efuse fields in a connected ESP bootloader
474472
"""
@@ -674,8 +672,9 @@ def burn_block(block, postponed_efuses):
674672
@staticmethod
675673
def confirm(action, do_not_confirm):
676674
log.print(
677-
"%s%s\nThis is an irreversible operation!"
678-
% (action, "" if action.endswith("\n") else ". ")
675+
"{}{}\nThis is an irreversible operation!".format(
676+
action, "" if action.endswith("\n") else ". "
677+
)
679678
)
680679
if not do_not_confirm:
681680
log.print("Type 'BURN' (all capitals) to continue.", flush=True)

espefuse/efuse/base_operations.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
import os
1010
import json
1111
import sys
12-
from typing import Any, BinaryIO, Callable, TextIO
12+
from typing import Any, BinaryIO, TextIO
13+
from collections.abc import Callable
1314

1415
import espsecure
1516
import rich_click as click
@@ -850,9 +851,9 @@ def print_attention(blocked_efuses_after_burn: list[str]):
850851
for block in self.efuses.blocks:
851852
burn_list_a_block = [e for e in burn_efuses_list if e.block == block.id]
852853
if len(burn_list_a_block):
853-
log.print(" from BLOCK%d" % (block.id))
854+
log.print(f" from BLOCK{block.id}")
854855
for field in burn_list_a_block:
855-
log.print(" - %s" % (field.name))
856+
log.print(f" - {field.name}")
856857
if (
857858
self.efuses.blocks[field.block].get_coding_scheme()
858859
!= self.efuses.REGS.CODING_SCHEME_NONE
@@ -990,7 +991,7 @@ def read_protect_efuse(self, efuse_names: list[str]):
990991
]
991992
if error:
992993
raise esptool.FatalError(
993-
"%s must be readable, stop this operation!" % efuse_name
994+
f"{efuse_name} must be readable, stop this operation!"
994995
)
995996
else:
996997
for block in self.efuses.Blocks.BLOCKS:
@@ -1000,8 +1001,8 @@ def read_protect_efuse(self, efuse_names: list[str]):
10001001
self.efuses[block.key_purpose].get()
10011002
):
10021003
raise esptool.FatalError(
1003-
"%s must be readable, stop this operation!"
1004-
% efuse_name
1004+
f"{efuse_name} must be readable, "
1005+
f"stop this operation!"
10051006
)
10061007
break
10071008
# make full list of which efuses will be disabled
@@ -1013,8 +1014,8 @@ def read_protect_efuse(self, efuse_names: list[str]):
10131014
]
10141015
names = ", ".join(e.name for e in all_disabling)
10151016
log.print(
1016-
"Permanently read-disabling eFuse%s %s"
1017-
% ("s" if len(all_disabling) > 1 else "", names)
1017+
f"Permanently read-disabling eFuse"
1018+
f"{'s' if len(all_disabling) > 1 else ''} {names}"
10181019
)
10191020
efuse.disable_read()
10201021

@@ -1055,8 +1056,8 @@ def write_protect_efuse(self, efuse_names: list[str]):
10551056
]
10561057
names = ", ".join(e.name for e in all_disabling)
10571058
log.print(
1058-
"Permanently write-disabling eFuse%s %s"
1059-
% ("s" if len(all_disabling) > 1 else "", names)
1059+
f"Permanently write-disabling eFuse"
1060+
f"{'s' if len(all_disabling) > 1 else ''} {names}"
10601061
)
10611062
efuse.disable_write()
10621063

@@ -1166,11 +1167,10 @@ def burn_bit(self, block: str, bit_number: list[int]):
11661167
)
11671168
data_block.reverse()
11681169
log.print(
1169-
"bit_number: "
1170-
"[%-03d]........................................................[0]"
1171-
% (data_block.len - 1)
1170+
f"bit_number: [{data_block.len - 1:03d}]"
1171+
f"........................................................[0]"
11721172
)
1173-
log.print("BLOCK%-2d :" % block_obj.id, data_block)
1173+
log.print(f"BLOCK{block_obj.id:>2d} :", data_block)
11741174
block_obj.print_block(data_block, "regs_to_write", debug=True)
11751175
block_obj.save(data_block.bytes[::-1])
11761176

espefuse/efuse/csv_table_parser.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def print_error(p, n, state):
180180
print_error(p, n, state)
181181

182182

183-
class FuseDefinition(object):
183+
class FuseDefinition:
184184
def __init__(self):
185185
self.field_name = ""
186186
self.group = ""
@@ -261,11 +261,9 @@ def get_alt_names(self, comment):
261261

262262
class InputError(RuntimeError):
263263
def __init__(self, e):
264-
super(InputError, self).__init__(e)
264+
super().__init__(e)
265265

266266

267267
class ValidationError(InputError):
268268
def __init__(self, p, message):
269-
super(ValidationError, self).__init__(
270-
f"Entry {p.field_name} invalid: {message}"
271-
)
269+
super().__init__(f"Entry {p.field_name} invalid: {message}")

espefuse/efuse/emulate_efuse_controller_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from esptool.logger import log
1111

1212

13-
class EmulateEfuseControllerBase(object):
13+
class EmulateEfuseControllerBase:
1414
"""The class for virtual efuse operations. Using for HOST_TEST."""
1515

1616
CHIP_NAME = ""

espefuse/efuse/esp32/emulate_efuse_controller.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def __init__(self, efuse_file=None, debug=False):
2222
self.Blocks = EfuseDefineBlocks
2323
self.Fields = EfuseDefineFields(None)
2424
self.REGS = EfuseDefineRegisters
25-
super(EmulateEfuseController, self).__init__(efuse_file, debug)
25+
super().__init__(efuse_file, debug)
2626

2727
""" esptool method start >> """
2828

@@ -39,7 +39,7 @@ def read_reg(self, addr):
3939
if addr == self.REGS.APB_CTL_DATE_ADDR:
4040
return self.REGS.APB_CTL_DATE_V << self.REGS.APB_CTL_DATE_S
4141
else:
42-
return super(EmulateEfuseController, self).read_reg(addr)
42+
return super().read_reg(addr)
4343

4444
""" << esptool method end """
4545

0 commit comments

Comments
 (0)