Skip to content

Commit 46309de

Browse files
committed
[section] Add Property.value deprecation warning
Closes #360 Using the 'value' attribute with the create_property method now elicits a 'warnings' module deprecation warning.
1 parent 6b73409 commit 46309de

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

odml/section.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
This module provides the Base Section class.
44
"""
55
import uuid
6+
import warnings
67

78
try:
89
from collections.abc import Iterable
@@ -774,21 +775,32 @@ def reorder(self, new_index):
774775

775776
return self._reorder(self.parent.sections, new_index)
776777

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):
778779
"""
779780
Create a new property that is a child of this section.
780781
781782
: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.
784785
:param dtype: The data type of the values stored in the property,
785786
if dtype is not given, the type is deduced from the values.
786787
Check odml.DType for supported data types.
787788
:param oid: object id, UUID string as specified in RFC 4122. If no id
788789
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+
789793
:return: The new property.
790794
"""
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)
792804
prop.parent = self
793805

794806
return prop

0 commit comments

Comments
 (0)