|
3 | 3 | This module provides the Base Section class.
|
4 | 4 | """
|
5 | 5 | import uuid
|
| 6 | +import warnings |
6 | 7 |
|
7 | 8 | try:
|
8 | 9 | from collections.abc import Iterable
|
@@ -774,21 +775,32 @@ def reorder(self, new_index):
|
774 | 775 |
|
775 | 776 | return self._reorder(self.parent.sections, new_index)
|
776 | 777 |
|
777 |
| - def create_property(self, name, value=None, dtype=None, oid=None): |
| 778 | + def create_property(self, name, values=None, dtype=None, oid=None, value=None): |
778 | 779 | """
|
779 | 780 | Create a new property that is a child of this section.
|
780 | 781 |
|
781 | 782 | :param name: The name of the property.
|
782 |
| - :param value: Some data value, it can be a single value or |
783 |
| - a list of homogeneous values. |
| 783 | + :param values: Some data value, it can be a single value or |
| 784 | + a list of homogeneous values. |
784 | 785 | :param dtype: The data type of the values stored in the property,
|
785 | 786 | if dtype is not given, the type is deduced from the values.
|
786 | 787 | Check odml.DType for supported data types.
|
787 | 788 | :param oid: object id, UUID string as specified in RFC 4122. If no id
|
788 | 789 | is provided, an id will be generated and assigned.
|
| 790 | + :param value: Deprecated alias of 'values'. Any content of 'value' is ignored, |
| 791 | + if 'values' is set. |
| 792 | +
|
789 | 793 | :return: The new property.
|
790 | 794 | """
|
791 |
| - prop = BaseProperty(name=name, value=value, dtype=dtype, oid=oid) |
| 795 | + if value and values: |
| 796 | + print("Warning: Both 'values' and 'value' were set; ignoring 'value'.") |
| 797 | + |
| 798 | + if not values and (value or isinstance(value, (bool, int))): |
| 799 | + msg = "The attribute 'value' is deprecated and will be removed, use 'values' instead." |
| 800 | + warnings.warn(msg, category=DeprecationWarning, stacklevel=2) |
| 801 | + values = value |
| 802 | + |
| 803 | + prop = BaseProperty(name=name, values=values, dtype=dtype, oid=oid) |
792 | 804 | prop.parent = self
|
793 | 805 |
|
794 | 806 | return prop
|
|
0 commit comments