Skip to content
Snippets Groups Projects

f kwargs to actual parameters

Merged Alexander Kreft requested to merge f-kwargs-to-parameters into dev
All threads resolved!
+ 56
53
@@ -426,7 +426,7 @@ class Entity(object):
return self
def add_parent(self, parent=None, **kwargs): # @ReservedAssignment
def add_parent(self, parent=None, id=None, name=None, inheritance=None): # @ReservedAssignment
"""Add a parent to this entity.
Parameters
@@ -434,27 +434,23 @@ class Entity(object):
parent : Entity or int or str or None
The parent entity, either specified by the Entity object
itself, or its id or its name. Default is None.
**kwargs : dict, optional
Additional keyword arguments for specifying the parent by
name or id, and for specifying the mode of inheritance.
id : int
Integer id of the parent entity. Ignored if `parent`
is not None.
name : str
Name of the parent entity. Ignored if `parent is not
none`.
inheritance : str
One of ``obligatory``, ``recommended``, ``suggested``, or ``fix``. Specifies the
minimum importance which parent properties need to have to be inherited by this
entity. If no `inheritance` is given, no properties will be inherited by the child.
This parameter is case-insensitive.
Note that the behaviour is currently not yet specified when assigning parents to
Records, it only works for inheritance of RecordTypes (and Properties).
For more information, it is recommended to look into the
:ref:`data insertion tutorial<tutorial-inheritance-properties>`.
id : int
Integer id of the parent entity. Ignored if `parent`
is not None.
name : str
Name of the parent entity. Ignored if `parent is not
none`.
inheritance : str
One of ``obligatory``, ``recommended``, ``suggested``, or ``fix``. Specifies the
minimum importance which parent properties need to have to be inherited by this
entity. If no `inheritance` is given, no properties will be inherited by the child.
This parameter is case-insensitive.
Note that the behaviour is currently not yet specified when assigning parents to
Records, it only works for inheritance of RecordTypes (and Properties).
For more information, it is recommended to look into the
:ref:`data insertion tutorial<tutorial-inheritance-properties>`.
Raises
------
@@ -463,8 +459,8 @@ class Entity(object):
parameter is passed to this method.
"""
name = (kwargs['name'] if 'name' in kwargs else None)
pid = (kwargs['id'] if 'id' in kwargs else None)
pid = id
parent_entity = None
if isinstance(parent, Entity):
@@ -478,9 +474,6 @@ class Entity(object):
raise UserWarning(
"This method expects you to pass at least an entity, a name or an id.")
inheritance = (kwargs['inheritance']
if 'inheritance' in kwargs else None)
addp = Parent(id=pid, name=name, inheritance=inheritance)
if parent_entity is not None:
@@ -1467,31 +1460,35 @@ class Property(Entity):
return super(Property, self).add_property(
property=property, value=value, **copy_kwargs)
def add_parent(self, parent=None, **kwargs):
def add_parent(self, parent=None, id=None, name=None, inheritance=FIX):
"""Add a parent Entity to this Property.
Parameters
----------
parent : Entity or int or str or None, optional
The parent entity
**kwargs : dict, optional
Additional keyword arguments specifying the parent Entity
by id or name, and specifying the inheritance level. See
:py:meth:`Entity.add_parent` for more information. Note
that by default, `inheritance` is set to ``fix``.
Parameters
----------
parent : Entity or int or str or None
The parent entity, either specified by the Entity object
itself, or its id or its name. Default is None.
id : int
Integer id of the parent entity. Ignored if `parent`
is not None.
name : str
Name of the parent entity. Ignored if `parent is not
none`.
inheritance : str, default: FIX
One of ``obligatory``, ``recommended``, ``suggested``, or ``fix``. Specifies the
minimum importance which parent properties need to have to be inherited by this
entity. If no `inheritance` is given, no properties will be inherited by the child.
This parameter is case-insensitive.
See Also
--------
Entity.add_parent
"""
copy_kwargs = kwargs.copy()
if 'inheritance' not in copy_kwargs:
# set default importance
copy_kwargs['inheritance'] = FIX
return super(Property, self).add_parent(parent=parent, **copy_kwargs)
return super(Property, self).add_parent(parent=parent, id=id, name=name, inheritance=inheritance)
def __init__(self, name=None, id=None, description=None, datatype=None,
value=None, unit=None):
@@ -1598,7 +1595,7 @@ class RecordType(Entity):
return super().add_property(property=property, value=value,
**copy_kwargs)
def add_parent(self, parent=None, **kwargs):
def add_parent(self, parent=None, id=None, name=None, inheritance=OBLIGATORY):
"""Add a parent to this RecordType
Parameters
@@ -1606,24 +1603,30 @@ class RecordType(Entity):
parent : Entity or int or str or None, optional
The parent entity, either specified by the Entity object
itself, or its id or its name. Default is None.
**kwargs : dict, optional
Additional keyword arguments specifying the parent Entity by id or
name, and specifying the inheritance level. See
:py:meth:`Entity.add_parent` for more information. Note
that by default, `inheritance` is set to ``obligatory``.
Parameters
----------
parent : Entity or int or str or None
The parent entity, either specified by the Entity object
itself, or its id or its name. Default is None.
id : int
Integer id of the parent entity. Ignored if `parent`
is not None.
name : str
Name of the parent entity. Ignored if `parent is not
none`.
inheritance : str, default OBLIGATORY
One of ``obligatory``, ``recommended``, ``suggested``, or ``fix``. Specifies the
minimum importance which parent properties need to have to be inherited by this
entity. If no `inheritance` is given, no properties will be inherited by the child.
This parameter is case-insensitive.
See Also
--------
Entity.add_parent
"""
copy_kwargs = kwargs.copy()
if 'inheritance' not in copy_kwargs:
# set default importance
copy_kwargs['inheritance'] = OBLIGATORY
return super().add_parent(parent=parent, **copy_kwargs)
return super().add_parent(parent=parent, id=id, name=name, inheritance=inheritance)
def __init__(self, name=None, id=None, description=None, datatype=None): # @ReservedAssignment
Entity.__init__(self, name=name, id=id, description=description,
Loading