Skip to content

Commit 475aec6

Browse files
committed
Numerous fixes for issues identified by LGTM.
- Fix for loop in TraceEventFilter. - Unused variable definitions. - Unreachable statements. - __eq__() not redefined when attributes were added to a subclass. - Unnecessary use of else branch on loop. - Raising NotImplemented instead of NotImplementedError. - Removed redefined GDBServer.restart(). - Duplicate dict keys. - Catchall exception handlers.
1 parent 6e7ef57 commit 475aec6

File tree

20 files changed

+33
-45
lines changed

20 files changed

+33
-45
lines changed

pyocd/commands/commands.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,7 +1028,6 @@ def parse(self, args):
10281028

10291029
def execute(self):
10301030
try:
1031-
type = self.context.selected_core.get_breakpoint_type(self.addr)
10321031
self.context.selected_core.remove_breakpoint(self.addr)
10331032
self.context.selected_core.bp_manager.flush()
10341033
self.context.writei("Removed breakpoint at 0x%08x", self.addr)
@@ -1158,7 +1157,6 @@ def execute(self):
11581157
if self.show_core:
11591158
self.context.writei("Core %d is selected", self.context.selected_core.core_number)
11601159
return
1161-
original_core_ap = core_ap = self.context.selected_core.ap
11621160
self.context.selected_core = self.context.session.target.cores[self.core_num]
11631161
core_ap = self.context.selected_core.ap
11641162
self.context.selected_ap_address = core_ap.address
@@ -1625,7 +1623,6 @@ def print_disasm(context, code, start_addr, max_instructions=None):
16251623
pc = -1
16261624
md = capstone.Cs(capstone.CS_ARCH_ARM, capstone.CS_MODE_THUMB)
16271625

1628-
addrLine = 0
16291626
text = ''
16301627
n = 0
16311628
for i in md.disasm(code, start_addr):

pyocd/commands/execution_context.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,6 @@ def parse_command(self, cmdline):
354354
", ".join("'%s'" % c for c in all_matches)))
355355
else:
356356
raise exceptions.CommandError("unrecognized command '%s'" % cmd)
357-
return
358357

359358
return CommandInvocation(matched_command, args, self.execute_command)
360359

pyocd/commands/values.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -531,11 +531,9 @@ def display(self, args):
531531
def modify(self, args):
532532
if len(args) < 1:
533533
raise exceptions.CommandError("no log level provided")
534-
return 1
535534
level_name = args[0].lower()
536535
if level_name not in self.LEVELS:
537536
raise exceptions.CommandError("log level must be one of {%s}" % ','.join(self.LEVELS.keys()))
538-
return 1
539537
level = self.LEVELS[level_name]
540538
if len(args) == 1:
541539
logging.getLogger().setLevel(level)
@@ -571,12 +569,10 @@ def display(self, args):
571569
def modify(self, args):
572570
if len(args) < 1:
573571
raise exceptions.CommandError("no clock frequency provided")
574-
return 1
575572
try:
576573
freq_Hz = convert_frequency(args[0])
577574
except:
578575
raise exceptions.CommandError("invalid frequency")
579-
return 1
580576
self.context.probe.set_clock(freq_Hz)
581577
if self.context.probe.wire_protocol == DebugProbe.Protocol.SWD:
582578
swd_jtag = 'SWD'

pyocd/core/memory_map.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,8 @@ def __copy__(self):
249249
**self._attributes
250250
)
251251

252-
def __hash__(self):
253-
# Need to redefine __hash__ since we redefine __eq__.
254-
return super(MemoryRegion, self).__hash__()
252+
# Need to redefine __hash__ since we redefine __eq__.
253+
__hash__ = MemoryRangeBase.__hash__
255254

256255
def __eq__(self, other):
257256
# Include type and attributes in equality comparison.
@@ -411,6 +410,14 @@ def __copy__(self):
411410
clone._flm = self._flm
412411
return clone
413412

413+
# Need to redefine __hash__ since we redefine __eq__.
414+
__hash__ = MemoryRegion.__hash__
415+
416+
def __eq__(self, other):
417+
# Include flash algo, class, and flm in equality test.
418+
return super(FlashRegion, self).__eq__(other) and self.algo == other.algo and \
419+
self.flash_class == other.flash_class and self.flm == other.flm
420+
414421
def __repr__(self):
415422
return "<%s@0x%x name=%s type=%s start=0x%x end=0x%x length=0x%x access=%s blocksize=0x%x>" % (self.__class__.__name__, id(self), self.name, self.type, self.start, self.end, self.length, self.access, self.blocksize)
416423

pyocd/core/options_manager.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# pyOCD debugger
2-
# Copyright (c) 2019 Arm Limited
2+
# Copyright (c) 2019-2020 Arm Limited
33
# SPDX-License-Identifier: Apache-2.0
44
#
55
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -116,8 +116,7 @@ def is_set(self, key):
116116
for layer in self._layers:
117117
if key in layer:
118118
return True
119-
else:
120-
return False
119+
return False
121120

122121
def get_default(self, key):
123122
"""! @brief Return the default value for the specified option."""

pyocd/coresight/ap.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def __init__(self, address):
197197
@property
198198
def ap_version(self):
199199
"""! @brief Version of the AP, as an APVersion enum."""
200-
raise NotImplemented()
200+
raise NotImplementedError()
201201

202202
@property
203203
def nominal_address(self):
@@ -212,12 +212,12 @@ def address(self):
212212
213213
This value can be passed to the DebugPort's read_ap() or write_ap() methods. Offsets of
214214
registers can be added to this value to create register addresses."""
215-
raise NotImplemented()
215+
raise NotImplementedError()
216216

217217
@property
218218
def idr_address(self):
219219
"""! @brief Address of the IDR register."""
220-
raise NotImplemented()
220+
raise NotImplementedError()
221221

222222
def __hash__(self):
223223
return hash(self.nominal_address)

pyocd/coresight/gpr.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# pyOCD debugger
2-
# Copyright (c) 2018 Arm Limited
2+
# Copyright (c) 2018,2020 Arm Limited
33
# SPDX-License-Identifier: Apache-2.0
44
#
55
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -66,8 +66,7 @@ def _power_up(self, mask):
6666
value = self.ap.read32(self.address + self.CPWRUPACK)
6767
if (value & mask) == mask:
6868
return True
69-
else:
70-
return False
69+
return False
7170

7271
def power_up_all(self):
7372
"""! @brief Enable power to all available power domains.

pyocd/debug/elf/elf.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ def flags_description(self):
7979
if flagsDesc[-1] == '|':
8080
flagsDesc = flagsDesc[:-1]
8181
return flagsDesc
82+
83+
def __eq__(self, other):
84+
# Include section name in equality test.
85+
return super(ELFSection, self).__eq__(other) and self.name == other.name
8286

8387
def __repr__(self):
8488
return "<ELFSection@0x{0:x} {1} {2} {3} {4} {5}>".format(

pyocd/gdbserver/gdbserver.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,10 +277,6 @@ def _init_remote_commands(self):
277277
# Add the gdbserver command group.
278278
self._command_context.command_set.add_command_group('gdbserver')
279279

280-
def restart(self):
281-
if self.is_alive():
282-
self.detach_event.set()
283-
284280
def stop(self):
285281
if self.is_alive():
286282
self.shutdown_event.set()

pyocd/probe/aggregator.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ def get_probe_with_id(cls, unique_id):
7878
probe = cls.get_probe_with_id(unique_id, is_explicit)
7979
if probe is not None:
8080
return probe
81-
else:
82-
return None
81+
return None
8382

8483
# Load plugins when this module is loaded.
8584
load_plugin_classes_of_type('pyocd.probe', PROBE_CLASSES, DebugProbe)

0 commit comments

Comments
 (0)