Skip to content
This repository was archived by the owner on Apr 22, 2024. It is now read-only.

Commit 1c267d4

Browse files
authored
Merge pull request #599 from gleybersonandrade/linter
Fix new linter issues
2 parents 0dae93b + a3bcc73 commit 1c267d4

File tree

15 files changed

+86
-116
lines changed

15 files changed

+86
-116
lines changed

pyof/foundation/base.py

Lines changed: 32 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def __str__(self):
7171
def __eq__(self, other):
7272
if isinstance(other, self.__class__):
7373
return self.pack() == other.pack()
74-
elif hasattr(other, 'value'):
74+
if hasattr(other, 'value'):
7575
return self.value == other.value
7676
return self.value == other
7777

@@ -141,10 +141,9 @@ def value(self):
141141
if isinstance(self._value, self.enum_ref):
142142
return self._value.value
143143
return self._value
144-
elif self.is_bitmask():
144+
if self.is_bitmask():
145145
return self._value.bitmask
146-
else:
147-
return self._value
146+
return self._value
148147

149148
def pack(self, value=None):
150149
r"""Pack the value as a binary representation.
@@ -272,10 +271,10 @@ class MetaStruct(type):
272271

273272
# pylint: disable=unused-argument
274273
@classmethod
275-
def __prepare__(mcs, name, bases, **kwargs):
274+
def __prepare__(cls, name, bases, **kwargs):
276275
return OrderedDict()
277276

278-
def __new__(mcs, name, bases, classdict, **kwargs):
277+
def __new__(cls, name, bases, classdict, **kwargs):
279278
"""Inherit attributes from parent class and update their versions.
280279
281280
Here is the moment that the new class is going to be created. During
@@ -321,7 +320,7 @@ class and place them as class attributes on the class being created.
321320
curr_version)
322321

323322
if attr_name == 'header':
324-
attr = mcs._header_message_type_update(obj, attr)
323+
attr = cls._header_message_type_update(obj, attr)
325324

326325
inherited_attributes.update([attr])
327326
#: We are going to inherit just from the 'closest parent'
@@ -341,7 +340,7 @@ class and place them as class attributes on the class being created.
341340
inherited_attributes.update(classdict)
342341
classdict = inherited_attributes
343342

344-
return super().__new__(mcs, name, bases, classdict, **kwargs)
343+
return super().__new__(cls, name, bases, classdict, **kwargs)
345344

346345
@staticmethod
347346
def _header_message_type_update(obj, attr):
@@ -478,7 +477,7 @@ def get_pyof_obj_new_version(name, obj, new_version):
478477
return (name, obj)
479478

480479

481-
class GenericStruct(object, metaclass=MetaStruct):
480+
class GenericStruct(metaclass=MetaStruct):
482481
"""Class inherited by all OpenFlow structs.
483482
484483
If you need to insert a method that will be used by all structs, this is
@@ -536,7 +535,7 @@ def _validate_attributes_type(self):
536535
for _attr, _class in self._get_attributes():
537536
if isinstance(_attr, _class):
538537
return True
539-
elif issubclass(_class, GenericType):
538+
if issubclass(_class, GenericType):
540539
if GenericStruct._attr_fits_into_class(_attr, _class):
541540
return True
542541
elif not isinstance(_attr, _class):
@@ -656,12 +655,10 @@ def get_size(self, value=None):
656655
if value is None:
657656
return sum(cls_val.get_size(obj_val) for obj_val, cls_val in
658657
self._get_attributes())
659-
elif isinstance(value, type(self)):
658+
if isinstance(value, type(self)):
660659
return value.get_size()
661-
else:
662-
msg = "{} is not an instance of {}".format(value,
663-
type(self).__name__)
664-
raise PackException(msg)
660+
msg = "{} is not an instance of {}".format(value, type(self).__name__)
661+
raise PackException(msg)
665662

666663
def pack(self, value=None):
667664
"""Pack the struct in a binary representation.
@@ -682,24 +679,21 @@ def pack(self, value=None):
682679
error_msg = "Error on validation prior to pack() on class "
683680
error_msg += "{}.".format(type(self).__name__)
684681
raise ValidationError(error_msg)
685-
else:
686-
message = b''
687-
# pylint: disable=no-member
688-
for attr_info in self._get_named_attributes():
689-
name, instance_value, class_value = attr_info
690-
try:
691-
message += class_value.pack(instance_value)
692-
except PackException as pack_exception:
693-
cls = type(self).__name__
694-
msg = f'{cls}.{name} - {pack_exception}'
695-
raise PackException(msg)
696-
return message
697-
elif isinstance(value, type(self)):
682+
message = b''
683+
# pylint: disable=no-member
684+
for attr_info in self._get_named_attributes():
685+
name, instance_value, class_value = attr_info
686+
try:
687+
message += class_value.pack(instance_value)
688+
except PackException as pack_exception:
689+
cls = type(self).__name__
690+
msg = f'{cls}.{name} - {pack_exception}'
691+
raise PackException(msg)
692+
return message
693+
if isinstance(value, type(self)):
698694
return value.pack()
699-
else:
700-
msg = "{} is not an instance of {}".format(value,
701-
type(self).__name__)
702-
raise PackException(msg)
695+
msg = "{} is not an instance of {}".format(value, type(self).__name__)
696+
raise PackException(msg)
703697

704698
def unpack(self, buff, offset=0):
705699
"""Unpack a binary struct into this object's attributes.
@@ -804,12 +798,10 @@ def pack(self, value=None):
804798
if value is None:
805799
self.update_header_length()
806800
return super().pack()
807-
elif isinstance(value, type(self)):
801+
if isinstance(value, type(self)):
808802
return value.pack()
809-
else:
810-
msg = "{} is not an instance of {}".format(value,
811-
type(self).__name__)
812-
raise PackException(msg)
803+
msg = "{} is not an instance of {}".format(value, type(self).__name__)
804+
raise PackException(msg)
813805

814806
def unpack(self, buff, offset=0):
815807
"""Unpack a binary message into this object's attributes.
@@ -850,7 +842,7 @@ class MetaBitMask(type):
850842
access object.ELEMENT and recover either values or names).
851843
"""
852844

853-
def __new__(mcs, name, bases, classdict):
845+
def __new__(cls, name, bases, classdict):
854846
"""Convert class attributes into enum elements."""
855847
_enum = OrderedDict([(key, value) for key, value in classdict.items()
856848
if key[0] != '_' and not
@@ -861,7 +853,7 @@ def __new__(mcs, name, bases, classdict):
861853
if key[0] == '_' or hasattr(value, '__call__') or
862854
isinstance(value, property)}
863855
classdict['_enum'] = _enum
864-
return type.__new__(mcs, name, bases, classdict)
856+
return type.__new__(cls, name, bases, classdict)
865857

866858
def __getattr__(cls, name):
867859
return cls._enum[name]
@@ -873,7 +865,7 @@ def __dir__(cls):
873865
return res
874866

875867

876-
class GenericBitMask(object, metaclass=MetaBitMask):
868+
class GenericBitMask(metaclass=MetaBitMask):
877869
"""Base class for enums that use bitmask values."""
878870

879871
def __init__(self, bitmask=None):

pyof/foundation/basic_types.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ def unpack(self, buff, offset=0):
5959
buff: Buffer where data is located.
6060
offset (int): Where data stream begins.
6161
"""
62-
pass
6362

6463
def pack(self, value=None):
6564
"""Pack the object.
@@ -472,12 +471,11 @@ def pack(self, value=None):
472471

473472
if hasattr(value, 'pack') and callable(value.pack):
474473
return value.pack()
475-
elif isinstance(value, bytes):
474+
if isinstance(value, bytes):
476475
return value
477-
elif value is None:
476+
if value is None:
478477
return b''
479-
else:
480-
raise ValueError(f"BinaryData can't be {type(value)} = '{value}'")
478+
raise ValueError(f"BinaryData can't be {type(value)} = '{value}'")
481479

482480
def unpack(self, buff, offset=0):
483481
"""Unpack a binary message into this object's attributes.
@@ -606,7 +604,7 @@ def get_size(self, value=None):
606604
if not self:
607605
# If this is a empty list, then returns zero
608606
return 0
609-
elif issubclass(type(self[0]), GenericType):
607+
if issubclass(type(self[0]), GenericType):
610608
# If the type of the elements is GenericType, then returns the
611609
# length of the list multiplied by the size of the GenericType.
612610
return len(self) * self[0].get_size()

pyof/foundation/exceptions.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,6 @@ def __str__(self):
5151
class UnpackException(Exception):
5252
"""Error while unpacking."""
5353

54-
pass
55-
5654

5755
class PackException(Exception):
5856
"""Error while unpacking."""
59-
60-
pass

pyof/foundation/network_types.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ def _validate(self):
188188
"""Assure this is a valid VLAN header instance."""
189189
if self.tpid.value not in (EtherType.VLAN, EtherType.VLAN_QINQ):
190190
raise UnpackException
191-
return
192191

193192
def unpack(self, buff, offset=0):
194193
"""Unpack a binary struct into this object's attributes.
@@ -409,13 +408,10 @@ def pack(self, value=None):
409408
output = self.header.pack()
410409
output += self.value.pack()
411410
return output
412-
413-
elif isinstance(value, type(self)):
411+
if isinstance(value, type(self)):
414412
return value.pack()
415-
else:
416-
msg = "{} is not an instance of {}".format(value,
417-
type(self).__name__)
418-
raise PackException(msg)
413+
msg = "{} is not an instance of {}".format(value, type(self).__name__)
414+
raise PackException(msg)
419415

420416
def unpack(self, buff, offset=0):
421417
"""Unpack a binary message into this object's attributes.

pyof/v0x01/asynchronous/error_msg.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,10 @@ def pack(self, value=None):
223223
if data_backup is not None:
224224
self.data = data_backup
225225
return packed
226-
elif isinstance(value, type(self)):
226+
if isinstance(value, type(self)):
227227
return value.pack()
228-
else:
229-
msg = "{} is not an instance of {}".format(value,
230-
type(self).__name__)
231-
raise PackException(msg)
228+
msg = "{} is not an instance of {}".format(value, type(self).__name__)
229+
raise PackException(msg)
232230

233231
def unpack(self, buff, offset=0):
234232
"""Unpack *buff* into this object.

pyof/v0x01/common/action.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class ActionOutput(ActionHeader):
119119
port = UBInt16()
120120
max_length = UBInt16()
121121

122-
_allowed_types = ActionType.OFPAT_OUTPUT,
122+
_allowed_types = (ActionType.OFPAT_OUTPUT,)
123123

124124
def __init__(self, port=None, max_length=UBINT16_MAX_VALUE):
125125
"""Create an ActionOutput with the optional parameters below.
@@ -143,7 +143,7 @@ class ActionStripVlan(ActionHeader):
143143

144144
pad = Pad(4)
145145

146-
_allowed_types = ActionType.OFPAT_STRIP_VLAN,
146+
_allowed_types = (ActionType.OFPAT_STRIP_VLAN,)
147147

148148
def __init__(self):
149149
"""Construct the ActionHeader with the appropriate ActionType.
@@ -168,7 +168,7 @@ class ActionEnqueue(ActionHeader):
168168
pad = Pad(6)
169169
queue_id = UBInt32()
170170

171-
_allowed_types = ActionType.OFPAT_ENQUEUE,
171+
_allowed_types = (ActionType.OFPAT_ENQUEUE,)
172172

173173
def __init__(self, port=None, queue_id=None):
174174
"""Create an ActionEnqueue with the optional parameters below.
@@ -194,7 +194,7 @@ class ActionVlanVid(ActionHeader):
194194
#: Pad for bit alignment.
195195
pad2 = Pad(2)
196196

197-
_allowed_types = ActionType.OFPAT_SET_VLAN_VID,
197+
_allowed_types = (ActionType.OFPAT_SET_VLAN_VID,)
198198

199199
def __init__(self, vlan_id=None):
200200
"""Create an ActionVlanVid with the optional parameters below.
@@ -213,7 +213,7 @@ class ActionVlanPCP(ActionHeader):
213213
#: Pad for bit alignment.
214214
pad = Pad(3)
215215

216-
_allowed_types = ActionType.OFPAT_SET_VLAN_PCP,
216+
_allowed_types = (ActionType.OFPAT_SET_VLAN_PCP,)
217217

218218
def __init__(self, vlan_pcp=None):
219219
"""Create an ActionVlanPCP with the optional parameters below.
@@ -282,7 +282,7 @@ class ActionNWTos(ActionHeader):
282282
#: Pad for bit alignment.
283283
pad = Pad(3)
284284

285-
_allowed_types = ActionType.OFPAT_SET_NW_TOS,
285+
_allowed_types = (ActionType.OFPAT_SET_NW_TOS,)
286286

287287
def __init__(self, action_type=None, nw_tos=None):
288288
"""Create an ActionNWTos with the optional parameters below.
@@ -327,7 +327,7 @@ class ActionVendorHeader(ActionHeader):
327327

328328
vendor = UBInt32()
329329

330-
_allowed_types = ActionType.OFPAT_VENDOR,
330+
_allowed_types = (ActionType.OFPAT_VENDOR,)
331331

332332
def __init__(self, length=None, vendor=None):
333333
"""Create an ActionVendorHeader with the optional parameters below.

pyof/v0x01/controller2switch/packet_out.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,10 @@ def pack(self, value=None):
6969
if value is None:
7070
self._update_actions_len()
7171
return super().pack()
72-
elif isinstance(value, type(self)):
72+
if isinstance(value, type(self)):
7373
return value.pack()
74-
else:
75-
msg = "{} is not an instance of {}".format(value,
76-
type(self).__name__)
77-
raise PackException(msg)
74+
msg = "{} is not an instance of {}".format(value, type(self).__name__)
75+
raise PackException(msg)
7876

7977
def unpack(self, buff, offset=0):
8078
"""Unpack a binary message into this object's attributes.

pyof/v0x01/controller2switch/stats_reply.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def _get_body_instance(self):
8383

8484
if pyof_class is None:
8585
return BinaryData(b'')
86-
elif pyof_class is DescStats:
86+
if pyof_class is DescStats:
8787
return pyof_class()
8888

8989
return FixedTypeList(pyof_class=pyof_class)

0 commit comments

Comments
 (0)