Skip to content

Commit c058de5

Browse files
committed
typos, typing, no bare except
1 parent e5b8916 commit c058de5

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

tools/upload.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
# If this fails, we can't continue and will bomb below
2626
try:
2727
import esptool
28-
except (ImportError, ModuleNotFoundError) as e:
28+
except ImportError:
2929
sys.stderr.write(
3030
"\n*** pyserial or esptool directories not found next to upload.py tool (this script) ***\n"
3131
)
@@ -38,16 +38,16 @@
3838
def make_erase_pair(addr: str, dest_size: int, block_size=2**16):
3939
dest, path = tempfile.mkstemp()
4040

41-
buffer = b"\xff" * block_size
41+
buffer = bytearray(b"\xff" * block_size)
4242
while dest_size:
4343
unaligned = dest_size % block_size
4444

45-
src_size = block_size
4645
if unaligned:
4746
src = buffer[unaligned:]
4847
src_size = unaligned
4948
else:
5049
src = buffer
50+
src_size = block_size
5151

5252
os.write(dest, src)
5353
dest_size -= src_size
@@ -57,7 +57,7 @@ def make_erase_pair(addr: str, dest_size: int, block_size=2**16):
5757
def maybe_remove(path):
5858
try:
5959
os.remove(path)
60-
except:
60+
except Exception:
6161
pass
6262

6363
atexit.register(maybe_remove, path)
@@ -66,9 +66,9 @@ def maybe_remove(path):
6666

6767
argv = sys.argv[1:] # Remove executable name
6868

69-
cmdline = [] # type: List[str]
70-
write_options = ["--flash_size", "detect"] # type: List[str]
71-
erase_options = []
69+
cmdline: List[str] = []
70+
write_options: List[str] = ["--flash_size", "detect"]
71+
erase_options: List[str] = []
7272

7373
thisarg = ""
7474
lastarg = ""
@@ -115,11 +115,11 @@ def maybe_remove(path):
115115

116116
try:
117117
esptool.main(cmdline)
118-
except:
118+
except Exception:
119119
etype, evalue, _ = sys.exc_info()
120120
estring = "\n".join(traceback.format_exception_only(etype, value=evalue))
121121

122-
sys.stderr.write(f"\n*** A fatal upload.py error occurred ***\n")
122+
sys.stderr.write("\n*** upload.py fatal error ***\n")
123123
sys.stderr.write(estring)
124124
sys.stderr.flush()
125125

0 commit comments

Comments
 (0)