Skip to content

Commit 0629dce

Browse files
committed
[base] PEP8 code cleanup
Reducing the impressive number of pylint warnings; this fixes the following issues: - no-else-raise - consider-using-in - import-outside-toplevel - inconsistent-return-statements - unnecessary-comprehension
1 parent c2b4a82 commit 0629dce

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

odml/base.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"""
33
This module provides base classes for functionality common to odML objects.
44
"""
5+
import copy
56
import posixpath
67

78
try:
@@ -36,9 +37,10 @@ def __eq__(self, obj):
3637
return False
3738

3839
for key in self._format:
39-
if key == "id" or key == "oid":
40+
if key in ["id", "oid"]:
4041
continue
41-
elif getattr(self, key) != getattr(obj, key):
42+
43+
if getattr(self, key) != getattr(obj, key):
4244
return False
4345

4446
return True
@@ -87,7 +89,6 @@ def clone(self, children=True):
8789
from this class.
8890
"""
8991
# TODO don't we need some recursion / deepcopy here?
90-
import copy
9192
obj = copy.copy(self)
9293
return obj
9394

@@ -149,6 +150,8 @@ def __contains__(self, key):
149150
if (hasattr(obj, "name") and obj.name == key) or key == obj:
150151
return True
151152

153+
return False
154+
152155
def __eq__(self, obj):
153156
"""
154157
SmartList attributes of 'sections' and 'properties' are
@@ -292,7 +295,7 @@ def extend(self, sec_list):
292295
if not isinstance(sec, BaseSection):
293296
raise ValueError("Can only extend objects of type Section.")
294297

295-
elif isinstance(sec, BaseSection) and sec.name in self._sections:
298+
if isinstance(sec, BaseSection) and sec.name in self._sections:
296299
raise KeyError("Section with name '%s' already exists." % sec.name)
297300

298301
for sec in sec_list:
@@ -356,9 +359,9 @@ def iterproperties(self, max_depth=None, filter_func=lambda x: True):
356359
iterable. Yields iterable if function returns True
357360
:type filter_func: function
358361
"""
359-
for sec in [s for s in self.itersections(max_depth=max_depth,
360-
yield_self=True)]:
361-
if hasattr(sec, "properties"): # not to fail if odml.Document
362+
for sec in list(self.itersections(max_depth=max_depth, yield_self=True)):
363+
# Avoid fail with an odml.Document
364+
if hasattr(sec, "properties"):
362365
for i in sec.properties:
363366
if filter_func(i):
364367
yield i
@@ -380,7 +383,7 @@ def itervalues(self, max_depth=None, filter_func=lambda x: True):
380383
iterable. Yields iterable if function returns True
381384
:type filter_func: function
382385
"""
383-
for prop in [p for p in self.iterproperties(max_depth=max_depth)]:
386+
for prop in list(self.iterproperties(max_depth=max_depth)):
384387
if filter_func(prop.values):
385388
yield prop.values
386389

@@ -478,9 +481,10 @@ def _get_section_by_path(self, path):
478481

479482
if found:
480483
return found._get_section_by_path("/".join(pathlist[1:]))
484+
481485
raise ValueError("Section named '%s' does not exist" % pathlist[0])
482-
else:
483-
return self._match_iterable(self.sections, pathlist[0])
486+
487+
return self._match_iterable(self.sections, pathlist[0])
484488

485489
def find(self, key=None, type=None, findAll=False, include_subtype=False):
486490
"""

0 commit comments

Comments
 (0)