Skip to content

Commit 69fac19

Browse files
committed
Annotation cleanup ebroecker#323
1 parent 2974476 commit 69fac19

12 files changed

+86
-84
lines changed

src/canmatrix/cancluster.py

+17-17
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@
22
from __future__ import absolute_import
33
import typing
44

5-
import canmatrix.canmatrix as cm
5+
import canmatrix
66

77

88
class CanCluster(dict):
99

1010
def __init__(self, *arg, **kw):
1111
super(CanCluster, self).__init__(*arg, **kw)
12-
self._frames = [] # type: typing.List[cm.Frame]
13-
self._signals = [] # type: typing.List[cm.Signal]
14-
self._ecus = [] # type: typing.List[cm.Ecu]
12+
self._frames = [] # type: typing.List[canmatrix.Frame]
13+
self._signals = [] # type: typing.List[canmatrix.Signal]
14+
self._ecus = [] # type: typing.List[canmatrix.Ecu]
1515
self.update()
1616

17-
def update_frames(self): # type: () -> typing.MutableSequence[cm.Frame]
18-
frames = [] # type: typing.List[cm.Frame]
17+
def update_frames(self): # type: () -> typing.MutableSequence[canmatrix.Frame]
18+
frames = [] # type: typing.List[canmatrix.Frame]
1919
frame_names = [] # type: typing.List[str]
2020
for matrixName in self:
21-
for frame in self[matrixName].frames: # type: cm.Frame
21+
for frame in self[matrixName].frames: # type: canmatrix.Frame
2222
if frame.name not in frame_names:
2323
frame_names.append(frame.name)
2424
frames.append(frame)
@@ -31,12 +31,12 @@ def update_frames(self): # type: () -> typing.MutableSequence[cm.Frame]
3131
self._frames = frames
3232
return frames
3333

34-
def update_signals(self): # type: () -> typing.MutableSequence[cm.Signal]
35-
signals = [] # type: typing.List[cm.Signal]
34+
def update_signals(self): # type: () -> typing.MutableSequence[canmatrix.Signal]
35+
signals = [] # type: typing.List[canmatrix.Signal]
3636
signal_names = [] # type: typing.List[str]
3737
for matrixName in self:
38-
for frame in self[matrixName].frames:
39-
for signal in frame.signals: # type: cm.Signal
38+
for frame in self[matrixName].frames: # type: canmatrix.Frame
39+
for signal in frame.signals:
4040
if signal.name not in signal_names:
4141
signal_names.append(signal.name)
4242
signals.append(signal)
@@ -47,11 +47,11 @@ def update_signals(self): # type: () -> typing.MutableSequence[cm.Signal]
4747
self._signals = signals
4848
return signals
4949

50-
def update_ecus(self): # type: () -> typing.MutableSequence[cm.Ecu]
51-
ecus = [] # type: typing.List[cm.Ecu]
50+
def update_ecus(self): # type: () -> typing.MutableSequence[canmatrix.Ecu]
51+
ecus = [] # type: typing.List[canmatrix.Ecu]
5252
ecu_names = [] # type: typing.List[str]
5353
for matrixName in self:
54-
for ecu in self[matrixName].ecus: # type: cm.Ecu
54+
for ecu in self[matrixName].ecus: # type: canmatrix.Ecu
5555
if ecu.name not in ecu_names:
5656
ecu_names.append(ecu.name)
5757
ecus.append(ecu)
@@ -64,19 +64,19 @@ def update(self):
6464
self.update_ecus()
6565

6666
@property
67-
def ecus(self): # type: () -> typing.MutableSequence[cm.Ecu]
67+
def ecus(self): # type: () -> typing.MutableSequence[canmatrix.Ecu]
6868
if not self._ecus:
6969
self.update_ecus()
7070
return self._ecus
7171

7272
@property
73-
def frames(self): # type: () -> typing.MutableSequence[cm.Frame]
73+
def frames(self): # type: () -> typing.MutableSequence[canmatrix.Frame]
7474
if not self._frames:
7575
self.update_frames()
7676
return self._frames
7777

7878
@property
79-
def signals(self): # type: () -> typing.MutableSequence[cm.Signal]
79+
def signals(self): # type: () -> typing.MutableSequence[canmatrix.Signal]
8080
if not self._signals:
8181
self.update_signals()
8282
return self._signals

src/canmatrix/canmatrix.py

+9-17
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,7 @@ def pgn(self, value): # type: (int) -> None
813813
@property
814814
def priority(self): # type: () -> int
815815
"""Get J1939 priority."""
816-
return self.arbitration_id.j1939_prio
816+
return self.arbitration_id.j1939_priority
817817

818818
@priority.setter
819819
def priority(self, value): # type: (int) -> None
@@ -1294,15 +1294,13 @@ def decode(self, data):
12941294

12951295
if self.is_complex_multiplexed:
12961296
decoded_values = dict()
1297-
filtered_signals = []
1298-
filtered_signals += self._filter_signals_for_multiplexer(None, None)
1297+
filtered_signals = self._filter_signals_for_multiplexer(None, None)
12991298

13001299
multiplex_name = None
13011300
multiplex_value = None
13021301

13031302
while self._has_sub_multiplexer(multiplex_name):
1304-
multiplex_name, multiplex_value = self._get_sub_multiplexer(multiplex_name, multiplex_value,
1305-
decoded)
1303+
multiplex_name, multiplex_value = self._get_sub_multiplexer(multiplex_name, multiplex_value, decoded)
13061304
decoded_values[multiplex_name] = decoded[multiplex_name]
13071305
filtered_signals += self._filter_signals_for_multiplexer(multiplex_name, multiplex_value)
13081306

@@ -1343,7 +1341,7 @@ def __init__(self, definition): # type (str) -> None
13431341
:param str definition: definition string. Ex: "INT -5 10"
13441342
"""
13451343
definition = definition.strip()
1346-
self.definition = definition # type: str
1344+
self.definition = definition
13471345
self.type = None # type: typing.Optional[str]
13481346
self.defaultValue = None # type: typing.Any
13491347

@@ -1561,40 +1559,34 @@ def add_define_default(self, name, value): # type: (str, typing.Any) -> None
15611559
def delete_obsolete_defines(self): # type: () -> None
15621560
"""Delete all unused Defines.
15631561
1564-
Delete them from frameDefines, buDefines and signalDefines.
1562+
Delete them from frame_defines, ecu_defines and signal_defines.
15651563
"""
15661564
defines_to_delete = set() # type: typing.Set[str]
1567-
for frameDef in self.frame_defines: # type: str
1568-
found = False
1565+
for frameDef in self.frame_defines:
15691566
for frame in self.frames:
15701567
if frameDef in frame.attributes:
1571-
found = True
15721568
break
1573-
if not found:
1569+
else:
15741570
defines_to_delete.add(frameDef)
15751571
for element in defines_to_delete:
15761572
del self.frame_defines[element]
15771573
defines_to_delete = set()
15781574
for ecu_define in self.ecu_defines:
1579-
found = False
15801575
for ecu in self.ecus:
15811576
if ecu_define in ecu.attributes:
1582-
found = True
15831577
break
1584-
if not found:
1578+
else:
15851579
defines_to_delete.add(ecu_define)
15861580
for element in defines_to_delete:
15871581
del self.ecu_defines[element]
15881582

15891583
defines_to_delete = set()
15901584
for signal_define in self.signal_defines:
1591-
found = False
15921585
for frame in self.frames:
15931586
for signal in frame.signals:
15941587
if signal_define in signal.attributes:
1595-
found = True
15961588
break
1597-
if not found:
1589+
else:
15981590
defines_to_delete.add(signal_define)
15991591
for element in defines_to_delete:
16001592
del self.signal_defines[element]

src/canmatrix/cli/compare.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,21 @@
2929
import typing
3030
import click
3131

32-
import attr
3332
import canmatrix.compare
3433

3534
logger = logging.getLogger(__name__)
3635

36+
3737
@click.command()
3838
@click.option('-v', '--verbose', 'verbosity', help="Output verbosity", count=True, default=1)
3939
@click.option('-s', '--silent', is_flag=True, default=False, help="don't print status messages to stdout. (only errors)")
4040
@click.option('-f', '--frames', is_flag=True, default=False, help="show list of frames")
4141
@click.option('-c', '--comments', 'check_comments', is_flag=True, default=False, help="look for changed comments")
4242
@click.option('-a', '--attributes', 'check_attributes', is_flag=True, default=False, help="look for changed attributes")
4343
@click.option('-t', '--valueTable', 'ignore_valuetables', is_flag=True, default=False, help="ignore changed valuetables")
44-
@click.argument('matrix1', required=1)
45-
@click.argument('matrix2', required=1)
46-
def cli_compare(matrix1, matrix2, verbosity, silent, check_comments, check_attributes, ignore_valuetables, frames): # type: () -> int
44+
@click.argument('matrix1', required=True)
45+
@click.argument('matrix2', required=True)
46+
def cli_compare(matrix1, matrix2, verbosity, silent, check_comments, check_attributes, ignore_valuetables, frames):
4747
"""
4848
canmatrix.cli.compare [options] matrix1 matrix2
4949
@@ -53,8 +53,6 @@ def cli_compare(matrix1, matrix2, verbosity, silent, check_comments, check_attri
5353
import canmatrix.log
5454
root_logger = canmatrix.log.setup_logger()
5555

56-
57-
5856
if silent:
5957
# Only print ERROR messages (ignore import warnings)
6058
verbosity = -1

src/canmatrix/cli/convert.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,15 @@
2626

2727
import logging
2828
import sys
29-
import typing
29+
3030
import click
3131

3232
import canmatrix.convert
33+
import canmatrix.log
3334

3435
logger = logging.getLogger(__name__)
3536

37+
3638
def get_formats():
3739
input = ""
3840
output = ""
@@ -43,6 +45,7 @@ def get_formats():
4345
output += suppFormat + "\n"
4446
return (input, output)
4547

48+
4649
@click.command()
4750
# global switches
4851
@click.option('-v', '--verbose', 'verbosity', count=True, default=1)
@@ -100,10 +103,10 @@ def get_formats():
100103
#sym switches
101104
@click.option('--symExportEncoding', 'symExportEncoding', default="iso-8859-1", help="Export charset of sym format, maybe utf-8\ndefault iso-8859-1")
102105
# in and out file
103-
@click.argument('infile', required=1)
104-
@click.argument('outfile', required=1)
105-
106-
def cli_convert(infile, outfile, silent, verbosity, **options): # type: () -> int
106+
@click.argument('infile', required=True)
107+
@click.argument('outfile', required=True)
108+
#
109+
def cli_convert(infile, outfile, silent, verbosity, **options):
107110
"""
108111
canmatrix.cli.convert [options] import-file export-file
109112
@@ -114,7 +117,7 @@ def cli_convert(infile, outfile, silent, verbosity, **options): # type: () -> i
114117

115118
root_logger = canmatrix.log.setup_logger()
116119

117-
if silent == True:
120+
if silent is True:
118121
# only print error messages, ignore verbosity flag
119122
verbosity = -1
120123
options["silent"] = True

src/canmatrix/convert.py

+21-19
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import sys
2727
import typing
2828

29-
import canmatrix.canmatrix as cm
29+
import canmatrix
3030
import canmatrix.copy
3131
import canmatrix.formats
3232
import canmatrix.log
@@ -42,25 +42,25 @@ def convert(infile, out_file_name, **options): # type: (str, str, **str) -> Non
4242

4343
logger.info("Exporting " + out_file_name + " ... ")
4444

45-
out_dbs = {}
45+
out_dbs = {} # type: typing.Dict[str, canmatrix.CanMatrix]
4646
for name in dbs:
4747
db = None
4848

4949
if 'ecus' in options and options['ecus'] is not None:
5050
ecu_list = options['ecus'].split(',')
51-
db = cm.CanMatrix()
51+
db = canmatrix.CanMatrix()
5252
for ecu in ecu_list:
5353
canmatrix.copy.copy_ecu_with_frames(ecu, dbs[name], db)
5454
if 'frames' in options and options['frames'] is not None:
5555
frame_list = options['frames'].split(',')
56-
db = cm.CanMatrix()
57-
for frame_name in frame_list: # type: str
58-
frame_to_copy = dbs[name].frame_by_name(frame_name) # type: cm.Frame
56+
db = canmatrix.CanMatrix()
57+
for frame_name in frame_list:
58+
frame_to_copy = dbs[name].frame_by_name(frame_name)
5959
canmatrix.copy.copy_frame(frame_to_copy.arbitration_id, dbs[name], db)
6060
if options.get('signals', False):
6161
signal_list = options['signals'].split(',')
62-
db = cm.CanMatrix()
63-
for signal_name in signal_list: # type: str
62+
db = canmatrix.CanMatrix()
63+
for signal_name in signal_list:
6464
canmatrix.copy.copy_signal(signal_name, dbs[name], db)
6565

6666
if db is None:
@@ -110,8 +110,8 @@ def convert(infile, out_file_name, **options): # type: (str, str, **str) -> Non
110110
for touple in touples:
111111
(frameName, ecu) = touple.split(':')
112112
frames = db.glob_frames(frameName)
113-
for frame in frames: # type: cm.Frame
114-
for signal in frame.signals: # type: cm.Signal
113+
for frame in frames:
114+
for signal in frame.signals:
115115
signal.add_receiver(ecu)
116116
frame.update_receiver()
117117

@@ -123,7 +123,7 @@ def convert(infile, out_file_name, **options): # type: (str, str, **str) -> Non
123123
change_tuples = options['changeFrameId'].split(',')
124124
for renameTuple in change_tuples:
125125
old, new = renameTuple.split(':')
126-
frame = db.frame_by_id(cm.ArbitrationId(int(old)))
126+
frame = db.frame_by_id(canmatrix.ArbitrationId(int(old)))
127127
if frame is not None:
128128
frame.arbitration_id.id = int(new)
129129
else:
@@ -144,20 +144,22 @@ def convert(infile, out_file_name, **options): # type: (str, str, **str) -> Non
144144
frame_ptr.del_attribute("VFrameFormat")
145145

146146
if 'skipLongDlc' in options and options['skipLongDlc'] is not None:
147-
delete_frame_list = [] # type: typing.List[cm.Frame]
148-
for frame in db.frames:
149-
if frame.size > int(options['skipLongDlc']):
150-
delete_frame_list.append(frame)
147+
delete_frame_list = [
148+
frame
149+
for frame in db.frames
150+
if frame.size > int(options['skipLongDlc'])
151+
]
151152
for frame in delete_frame_list:
152153
db.del_frame(frame)
153154

154155
if 'cutLongFrames' in options and options['cutLongFrames'] is not None:
155156
for frame in db.frames:
156157
if frame.size > int(options['cutLongFrames']):
157-
delete_signal_list = []
158-
for sig in frame.signals:
159-
if sig.get_startbit() + int(sig.size) > int(options['cutLongFrames'])*8:
160-
delete_signal_list.append(sig)
158+
delete_signal_list = [
159+
sig
160+
for sig in frame.signals
161+
if sig.get_startbit() + int(sig.size) > int(options['cutLongFrames'])*8
162+
]
161163
for sig in delete_signal_list:
162164
frame.signals.remove(sig)
163165
frame.size = 0

src/canmatrix/formats/__init__.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
supportedFormats[loadedModule].append("clusterExporter")
4040
if "extension" in dir(moduleInstance):
4141
supportedFormats[loadedModule].append("extension")
42-
extensionMapping[loadedModule] = moduleInstance.extension
42+
extensionMapping[loadedModule] = moduleInstance.extension # type: ignore
4343
else:
4444
extensionMapping[loadedModule] = loadedModule
4545

@@ -101,7 +101,7 @@ def load_flat(file_object, import_type, key="", **options):
101101

102102

103103
def dump(can_matrix_or_cluster, file_object, export_type, **options):
104-
# type: (typing.Union[canmatrix.CanMatrix, canmatrix.cancluster.CanCluster], typing.IO, str, **str) -> None
104+
# type: (typing.Union[canmatrix.CanMatrix, typing.Mapping[str, canmatrix.CanMatrix]], typing.IO, str, **str) -> None
105105
module_instance = sys.modules["canmatrix.formats." + export_type]
106106
if isinstance(can_matrix_or_cluster, canmatrix.CanMatrix):
107107
module_instance.dump(can_matrix_or_cluster, file_object, **options) # type: ignore
@@ -110,7 +110,7 @@ def dump(can_matrix_or_cluster, file_object, export_type, **options):
110110

111111

112112
def dumpp(can_cluster, path, export_type=None, **options):
113-
# type: (canmatrix.cancluster.CanCluster, str, str, **str) -> None
113+
# type: (typing.Mapping[str, canmatrix.CanMatrix], str, str, **str) -> None
114114
if not export_type:
115115
for key, extension in extensionMapping.items():
116116
if path.lower().endswith("." + extension) and "dump" in supportedFormats[key]:

0 commit comments

Comments
 (0)