diff --git a/.idea/pySBOL3.iml b/.idea/pySBOL3.iml index 475d9e2..a6d5897 100644 --- a/.idea/pySBOL3.iml +++ b/.idea/pySBOL3.iml @@ -2,6 +2,7 @@ + diff --git a/sbol3/object.py b/sbol3/object.py index 208bacd..394d1a7 100644 --- a/sbol3/object.py +++ b/sbol3/object.py @@ -1,9 +1,8 @@ import posixpath import uuid -import warnings from collections import defaultdict from urllib.parse import urlparse -from typing import Dict, Callable, Optional +from typing import Dict, Callable, Optional, Union from . import * @@ -23,14 +22,14 @@ def __setattr__(self, name, value): self.__dict__[name].set(value) except AttributeError: # Attribute set does not exist - object.__setattr__(self, name, value) + super().__setattr__(name, value) except KeyError: # property name does not exist - object.__setattr__(self, name, value) + super().__setattr__(name, value) def __getattribute__(self, name): # Call the default method - result = object.__getattribute__(self, name) + result = super().__getattribute__(name) if hasattr(result, '_sbol_singleton'): result = result.get() return result @@ -41,7 +40,7 @@ def _is_url(name: str) -> bool: return bool(parsed.scheme and parsed.netloc and parsed.path) @staticmethod - def _make_identity(name: str) -> str: + def _make_identity(name: str) -> Union[str, None]: """Make an identity from the given name. If the name is a URL, that can be the identity. Or perhaps it @@ -108,18 +107,17 @@ def copy(self, target_doc=None, target_namespace=None): old_uri = self.identity new_uri = replace_namespace(old_uri, target_namespace, self.getTypeURI()) - new_obj = BUILDER_REGISTER[self.type_uri](identity=new_uri, - type_uri=self.type_uri) + new_obj = BUILDER_REGISTER[self.type_uri](**dict(identity=new_uri, + type_uri=self.type_uri)) # Copy properties for property_uri, value_store in self._properties.items(): new_obj._properties[property_uri] = value_store.copy() - # TODO: - # Map into new namespace + # TODO: Map into new namespace # Assign the new object to the target Document - if target_doc: + if target_doc is not None: try: target_doc.add(new_obj) except TypeError: diff --git a/test/test_object.py b/test/test_object.py index 2a0137b..f974d48 100644 --- a/test/test_object.py +++ b/test/test_object.py @@ -44,6 +44,7 @@ def test_copy_child_objects(self): doc2 = sbol3.Document() root_copy = root.copy(target_doc=doc2) + self.assertIn(root_copy, doc2.objects) self.assertEqual([sc.identity for sc in root.features], [sc.identity for sc in root_copy.features])