diff --git a/src/caosdb/common/models.py b/src/caosdb/common/models.py index 6d30e64b124e43b0bda779e0206aef5ba3080a92..bd28ca20f9560e18b15e35a832b5bbf83c0ed300 100644 --- a/src/caosdb/common/models.py +++ b/src/caosdb/common/models.py @@ -339,18 +339,19 @@ class Entity(object): return self - def add_property(self, property=None, value=None, **kwargs): # @ReservedAssignment + def add_property(self, property=None, value=None, id=None, name=None, description=None, datatype=None, + unit=None, importance=None, inheritance=None): # @ReservedAssignment """Add a property to this entity. The first parameter is meant to identify the property entity. So the method expects an instance of Entity, an integer or a string here. The second parameter is the value of the new property. Any - other named parameter may be passed by means of the **kwargs. Accepted keywords are: + other named parameter may be passed by means of the keywwords. Accepted keywords are: id, name, description, importance, inheritance, datatype, and unit. Any other keyword will be ignored right now. But that may change in the future. @param property: An identifying parameter (name, id or abstract property). @param value: The value of the new property. - @param **kwargs: Any other specification for this property. Accepted keywords: id, name, description, importance, inheritance, datatype, and unit. + @param Any other specification for this property. Accepted keywords: id, name, description, importance, inheritance, datatype, and unit. @raise UserWarning: If the first parameter is None then kwargs['id'] or kwargs['name'] must be defined and not be None. Otherwise a UserWarning is raised. @@ -362,9 +363,8 @@ class Entity(object): interpreted as the name and kwargs['name'] must be undefined or None. Otherwise a UserWarning is raised. """ - copy_kwargs = kwargs.copy() - name = (kwargs['name'] if 'name' in kwargs else None) - pid = (kwargs['id'] if 'id' in kwargs else None) + + pid = id abstract_property = None if isinstance(property, Entity): @@ -373,20 +373,18 @@ class Entity(object): if pid is not None: raise UserWarning("The first parameter was an integer which would normally be interpreted as the id of the property which is to be added. But you have also specified a parameter 'id' in the method call. This is ambiguous and cannot be processed.") pid = property - copy_kwargs['id'] = pid + id = pid elif property is not None: if name is not None: raise UserWarning("The first parameter was neither an instance of Entity nor an integer. Therefore the string representation of your first parameter would normally be interpreted name of the property which is to be added. But you have also specified a parameter 'name' in the method call. This is ambiguous and cannot be processed.") name = str(property) - copy_kwargs['name'] = name if property is None and name is None and pid is None: raise UserWarning( "This method expects you to pass at least an entity, a name or an id.") - del copy_kwargs['importance'] - del copy_kwargs['inheritance'] - new_property = Property(**copy_kwargs) + new_property = Property(name=name, id=id, description=description, datatype=datatype, + value=value, unit=unit) if abstract_property is not None: new_property._wrap(property) @@ -399,9 +397,7 @@ class Entity(object): new_property.value = value self.properties.append( - property=new_property, importance=( - kwargs['importance'] if 'importance' in kwargs else None), inheritance=( - kwargs['inheritance'] if 'inheritance' in kwargs else None)) + property=new_property, importance=importance, inheritance=inheritance) return self @@ -1446,19 +1442,12 @@ class Property(Entity): """CaosDB's Property object.""" - def add_property(self, property=None, value=None, **kwargs): # @ReservedAssignment - copy_kwargs = kwargs.copy() - - if 'importance' not in copy_kwargs: - # set default importance - copy_kwargs['importance'] = FIX + def add_property(self, property=None, value=None, id=None, name=None, description=None, datatype=None, + unit=None, importance=FIX, inheritance=FIX): # @ReservedAssignment - if 'inheritance' not in copy_kwargs: - # set default importance - copy_kwargs['inheritance'] = FIX - - return super(Property, self).add_property( - property=property, value=value, **copy_kwargs) + return super().add_property( + property=property, id=id, name=name, description=description, datatype=datatype, + value=value, unit=unit, importance=importance, inheritance=inheritance) def add_parent(self, parent=None, id=None, name=None, inheritance=FIX): """Add a parent Entity to this Property. @@ -1581,19 +1570,12 @@ class RecordType(Entity): """This class represents CaosDB's RecordType entities.""" - def add_property(self, property=None, value=None, **kwargs): # @ReservedAssignment - copy_kwargs = kwargs.copy() - - if 'importance' not in copy_kwargs: - # set default importance - copy_kwargs['importance'] = RECOMMENDED + def add_property(self, property=None, value=None, id=None, name=None, description=None, datatype=None, + unit=None, importance=RECOMMENDED, inheritance=FIX): # @ReservedAssignment - if 'inheritance' not in copy_kwargs: - # set default importance - copy_kwargs['inheritance'] = FIX - - return super().add_property(property=property, value=value, - **copy_kwargs) + return super().add_property( + property=property, id=id, name=name, description=description, datatype=datatype, + value=value, unit=unit, importance=importance, inheritance=inheritance) def add_parent(self, parent=None, id=None, name=None, inheritance=OBLIGATORY): """Add a parent to this RecordType @@ -1643,19 +1625,12 @@ class Record(Entity): """This class represents CaosDB's Record entities.""" - def add_property(self, property=None, value=None, **kwargs): # @ReservedAssignment - copy_kwargs = kwargs.copy() - - if 'importance' not in copy_kwargs: - # set default importance - copy_kwargs['importance'] = FIX - - if 'inheritance' not in copy_kwargs: - # set default importance - copy_kwargs['inheritance'] = FIX + def add_property(self, property=None, value=None, id=None, name=None, description=None, datatype=None, + unit=None, importance=FIX, inheritance=FIX): # @ReservedAssignment return super().add_property( - property=property, value=value, **copy_kwargs) + property=property, id=id, name=name, description=description, datatype=datatype, + value=value, unit=unit, importance=importance, inheritance=inheritance) def __init__(self, name=None, id=None, description=None): # @ReservedAssignment Entity.__init__(self, name=name, id=id, description=description, @@ -1807,19 +1782,12 @@ class File(Record): return checksum.hexdigest() - def add_property(self, property=None, value=None, **kwargs): # @ReservedAssignment - copy_kwargs = kwargs.copy() - - if 'importance' not in copy_kwargs: - # set default importance - copy_kwargs['importance'] = FIX - - if 'inheritance' not in copy_kwargs: - # set default importance - copy_kwargs['inheritance'] = FIX + def add_property(self, property=None, id=None, name=None, description=None, datatype=None, + value=None, unit=None, importance=FIX, inheritance=FIX): # @ReservedAssignment return super().add_property( - property=property, value=value, **copy_kwargs) + property=property, id=id, name=name, description=description, datatype=datatype, + value=value, unit=unit, importance=importance, inheritance=inheritance) class _Properties(list):