Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fixed Inconsistent return statements #467

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions sbol3/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,7 @@ def file_extension(file_format: str) -> str:
}
if file_format in types_with_standard_extension:
return types_with_standard_extension[file_format]
else:
raise ValueError('Provided file format is not a valid one.')
raise ValueError('Provided file format is not a valid one.')

# Formats: 'n3', 'nt', 'turtle', 'xml'
def read(self, location: Union[Path, str], file_format: str = None) -> None:
Expand Down Expand Up @@ -394,8 +393,7 @@ def add(self,
# Now dispatch to the appropriate method
if isinstance(objects, TopLevel):
return self._add(objects)
else:
return self._add_all(objects)
return self._add_all(objects)

def _find_in_objects(self, search_string: str) -> Optional[Identified]:
# TODO: implement recursive search
Expand Down Expand Up @@ -428,13 +426,19 @@ def join_lines(self, lines: List[Union[bytes, str]]) -> Union[bytes, str]:
"""
if not lines:
return ''
lines_type = type(lines[0])

first_line = lines[0]
lines_type = type(first_line)

if lines_type is bytes:
# rdflib 5
return b'\n'.join(lines) + b'\n'
newline = b'\n'
elif lines_type is str:
# rdflib 6
return '\n'.join(lines) + '\n'
newline = '\n'
else:
raise ValueError("Lines must be either bytes or str")

joined = newline.join(lines)
return joined + newline

def write_string(self, file_format: str) -> str:
graph = self.graph()
Expand Down
5 changes: 2 additions & 3 deletions sbol3/identified.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,12 @@ def extract_display_id(identity: str) -> Union[None, str]:
# and display id is optional in this case
return None
display_id = parsed.path.split('/')[-1]
if is_valid_display_id(display_id):
return display_id
else:
if not is_valid_display_id(display_id):
msg = f'"{display_id}" is not a valid displayId.'
msg += ' A displayId MUST be composed of only alphanumeric'
msg += ' or underscore characters and MUST NOT begin with a digit.'
raise ValueError(msg)
return display_id


class Identified(SBOLObject):
Expand Down
4 changes: 2 additions & 2 deletions sbol3/object.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ def _make_identity(name: str) -> Union[str, None]:
base_uri = PYSBOL3_DEFAULT_NAMESPACE
if base_uri.endswith('#'):
return base_uri + name
else:
return posixpath.join(base_uri, name.lstrip(posixpath.sep))

return posixpath.join(base_uri, name.lstrip(posixpath.sep))

@property
def identity(self) -> str:
Expand Down
11 changes: 5 additions & 6 deletions sbol3/property_base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import abc
import collections
from collections.abc import MutableSequence, Iterable
from typing import Any, Optional, List, Dict, Union
from collections.abc import Iterable, MutableSequence
from typing import Any, Dict, List, Optional, Union

from sbol3 import ValidationReport

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

def __len__(self) -> int:
return self._storage()[self.property_uri].__len__()
Expand Down
8 changes: 4 additions & 4 deletions sbol3/refobj_property.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import Union, Any, List, Optional
from typing import Any, List, Optional, Union

import rdflib

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

# TODO: Should the lack of a parent raise an error?
return None


class ReferencedObjectMixin:
Expand Down
2 changes: 1 addition & 1 deletion sbol3/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def parse_class_name(uri: str):
"""
if '#' in uri:
return uri[uri.rindex('#')+1:]
elif '/' in uri:
if '/' in uri:
return uri[uri.rindex('/')+1:]
raise ValueError(f'Cannot parse class name from {uri}. URI must use either / '
'or # as a delimiter.')
17 changes: 9 additions & 8 deletions sbol3/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ def __init__(self, object_id, rule_id, message):
self.object_id = object_id

def __str__(self):
if self.object_id and self.rule_id:
return f'{self.object_id} {self.rule_id}: {self.message}'
elif self.object_id:
return f'{self.object_id}: {self.message}'
elif self.rule_id:
return f'{self.rule_id}: {self.message}'
else:
return self.message
parts = [] # list of parts to include in the message

if self.object_id:
parts.append(str(self.object_id)) # add the object ID if present
if self.rule_id:
parts.append(str(self.rule_id)) # add the rule ID if present if present

# return the message with the parts if parts exits otherwise just the message
return f"{' '.join(parts)}: {self.message}" if parts else self.message


class ValidationError(ValidationIssue):
Expand Down
2 changes: 0 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@ disable = abstract-class-instantiated,
fixme,
function-redefined,
global-statement,
inconsistent-return-statements,
invalid-name,
isinstance-second-argument-not-valid-type,
missing-class-docstring,
missing-function-docstring,
missing-module-docstring,
no-else-return,
protected-access,
raise-missing-from,
redefined-builtin,
Expand Down
7 changes: 4 additions & 3 deletions test/test_roundtrip.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,12 @@ def rdf_type(filename: str):
'jsonld': sbol3.JSONLD,
'jsonld_expanded': sbol3.JSONLD,
}
if ext in ext_map:
return ext_map[ext]
else:

if ext not in ext_map:
return None

return ext_map[ext]

def test_read_all(self):
# In lieu of round tripping the files, just make sure we can
# read them all.
Expand Down