Skip to content

Commit e3962a3

Browse files
authored
Merge pull request #467 from GeneCodeSavvy/inconsistent-return-statements
Fixed Inconsistent return statements
2 parents 34fcc5e + 68b3a1a commit e3962a3

9 files changed

+40
-38
lines changed

sbol3/document.py

+13-9
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,7 @@ def file_extension(file_format: str) -> str:
315315
}
316316
if file_format in types_with_standard_extension:
317317
return types_with_standard_extension[file_format]
318-
else:
319-
raise ValueError('Provided file format is not a valid one.')
318+
raise ValueError('Provided file format is not a valid one.')
320319

321320
# Formats: 'n3', 'nt', 'turtle', 'xml'
322321
def read(self, location: Union[Path, str], file_format: str = None) -> None:
@@ -394,8 +393,7 @@ def add(self,
394393
# Now dispatch to the appropriate method
395394
if isinstance(objects, TopLevel):
396395
return self._add(objects)
397-
else:
398-
return self._add_all(objects)
396+
return self._add_all(objects)
399397

400398
def _find_in_objects(self, search_string: str) -> Optional[Identified]:
401399
# TODO: implement recursive search
@@ -428,13 +426,19 @@ def join_lines(self, lines: List[Union[bytes, str]]) -> Union[bytes, str]:
428426
"""
429427
if not lines:
430428
return ''
431-
lines_type = type(lines[0])
429+
430+
first_line = lines[0]
431+
lines_type = type(first_line)
432+
432433
if lines_type is bytes:
433-
# rdflib 5
434-
return b'\n'.join(lines) + b'\n'
434+
newline = b'\n'
435435
elif lines_type is str:
436-
# rdflib 6
437-
return '\n'.join(lines) + '\n'
436+
newline = '\n'
437+
else:
438+
raise ValueError("Lines must be either bytes or str")
439+
440+
joined = newline.join(lines)
441+
return joined + newline
438442

439443
def write_string(self, file_format: str) -> str:
440444
graph = self.graph()

sbol3/identified.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,12 @@ def extract_display_id(identity: str) -> Union[None, str]:
5252
# and display id is optional in this case
5353
return None
5454
display_id = parsed.path.split('/')[-1]
55-
if is_valid_display_id(display_id):
56-
return display_id
57-
else:
55+
if not is_valid_display_id(display_id):
5856
msg = f'"{display_id}" is not a valid displayId.'
5957
msg += ' A displayId MUST be composed of only alphanumeric'
6058
msg += ' or underscore characters and MUST NOT begin with a digit.'
6159
raise ValueError(msg)
60+
return display_id
6261

6362

6463
class Identified(SBOLObject):

sbol3/object.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ def _make_identity(name: str) -> Union[str, None]:
7676
base_uri = PYSBOL3_DEFAULT_NAMESPACE
7777
if base_uri.endswith('#'):
7878
return base_uri + name
79-
else:
80-
return posixpath.join(base_uri, name.lstrip(posixpath.sep))
79+
80+
return posixpath.join(base_uri, name.lstrip(posixpath.sep))
8181

8282
@property
8383
def identity(self) -> str:

sbol3/property_base.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import abc
22
import collections
3-
from collections.abc import MutableSequence, Iterable
4-
from typing import Any, Optional, List, Dict, Union
3+
from collections.abc import Iterable, MutableSequence
4+
from typing import Any, Dict, List, Optional, Union
55

66
from sbol3 import ValidationReport
77

@@ -127,11 +127,10 @@ def __getitem__(self, key: Union[int, slice]) -> Any:
127127
value = self._storage()[self.property_uri].__getitem__(key)
128128
if isinstance(value, str):
129129
return self.to_user(value)
130-
elif isinstance(value, collections.abc.Iterable):
130+
if isinstance(value, collections.abc.Iterable):
131131
return [self.to_user(v) for v in value]
132-
else:
133-
# Not a string or an iterable, just convert
134-
return self.to_user(value)
132+
# Not a string or an iterable, just convert -- Fallback
133+
return self.to_user(value)
135134

136135
def __len__(self) -> int:
137136
return self._storage()[self.property_uri].__len__()

sbol3/refobj_property.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
from typing import Union, Any, List, Optional
3+
from typing import Any, List, Optional, Union
44

55
import rdflib
66

@@ -15,9 +15,9 @@ def __eq__(self, other):
1515
def lookup(self):
1616
if hasattr(self, 'parent'):
1717
return self.parent.document.find(str(self))
18-
else:
19-
# TODO: Should the lack of a parent raise an error?
20-
return None
18+
19+
# TODO: Should the lack of a parent raise an error?
20+
return None
2121

2222

2323
class ReferencedObjectMixin:

sbol3/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def parse_class_name(uri: str):
99
"""
1010
if '#' in uri:
1111
return uri[uri.rindex('#')+1:]
12-
elif '/' in uri:
12+
if '/' in uri:
1313
return uri[uri.rindex('/')+1:]
1414
raise ValueError(f'Cannot parse class name from {uri}. URI must use either / '
1515
'or # as a delimiter.')

sbol3/validation.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@ def __init__(self, object_id, rule_id, message):
1111
self.object_id = object_id
1212

1313
def __str__(self):
14-
if self.object_id and self.rule_id:
15-
return f'{self.object_id} {self.rule_id}: {self.message}'
16-
elif self.object_id:
17-
return f'{self.object_id}: {self.message}'
18-
elif self.rule_id:
19-
return f'{self.rule_id}: {self.message}'
20-
else:
21-
return self.message
14+
parts = [] # list of parts to include in the message
15+
16+
if self.object_id:
17+
parts.append(str(self.object_id)) # add the object ID if present
18+
if self.rule_id:
19+
parts.append(str(self.rule_id)) # add the rule ID if present if present
20+
21+
# return the message with the parts if parts exits otherwise just the message
22+
return f"{' '.join(parts)}: {self.message}" if parts else self.message
2223

2324

2425
class ValidationError(ValidationIssue):

setup.cfg

-2
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,11 @@ disable = abstract-class-instantiated,
2121
fixme,
2222
function-redefined,
2323
global-statement,
24-
inconsistent-return-statements,
2524
invalid-name,
2625
isinstance-second-argument-not-valid-type,
2726
missing-class-docstring,
2827
missing-function-docstring,
2928
missing-module-docstring,
30-
no-else-return,
3129
protected-access,
3230
raise-missing-from,
3331
redefined-builtin,

test/test_roundtrip.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,12 @@ def rdf_type(filename: str):
8484
'jsonld': sbol3.JSONLD,
8585
'jsonld_expanded': sbol3.JSONLD,
8686
}
87-
if ext in ext_map:
88-
return ext_map[ext]
89-
else:
87+
88+
if ext not in ext_map:
9089
return None
9190

91+
return ext_map[ext]
92+
9293
def test_read_all(self):
9394
# In lieu of round tripping the files, just make sure we can
9495
# read them all.

0 commit comments

Comments
 (0)