Skip to content

Commit 6b73409

Browse files
committed
[property] Unify 'value' deprecation warning
All usages of the Property attribute 'value' now elicit a 'warnings' DeprecationWarning.
1 parent 5cc1d34 commit 6b73409

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

odml/property.py

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

78
from . import base
89
from . import dtypes
@@ -12,6 +13,10 @@
1213
from .util import format_cardinality
1314

1415

16+
MSG_VALUE_DEPRECATION = "The attribute 'value' is deprecated and will be removed, " \
17+
"use 'values' instead."
18+
19+
1520
def odml_tuple_import(t_count, new_value):
1621
"""
1722
Checks via a heuristic if the values in a string fit the general
@@ -131,6 +136,8 @@ def __init__(self, name=None, values=None, parent=None, unit=None,
131136
self._values = []
132137
self.values = values
133138
if not values and (value or isinstance(value, (bool, int))):
139+
# Using stacklevel=2 to avoid file name and code line in the message output.
140+
warnings.warn(MSG_VALUE_DEPRECATION, category=DeprecationWarning, stacklevel=2)
134141
self.values = value
135142

136143
self.parent = parent
@@ -285,7 +292,9 @@ def value(self):
285292
"""
286293
Deprecated alias of 'values'. Will be removed with the next minor release.
287294
"""
288-
print("The attribute 'value' is deprecated. Please use 'values' instead.")
295+
# Using stacklevel=2 to avoid file name and code line in the message output.
296+
warnings.warn(MSG_VALUE_DEPRECATION, category=DeprecationWarning, stacklevel=2)
297+
289298
return self.values
290299

291300
@value.setter
@@ -295,7 +304,8 @@ def value(self, new_value):
295304
296305
:param new_value: a single value or list of values.
297306
"""
298-
print("The attribute 'value' is deprecated. Please use 'values' instead.")
307+
# Using stacklevel=2 to avoid file name and code line in the message output.
308+
warnings.warn(MSG_VALUE_DEPRECATION, category=DeprecationWarning, stacklevel=2)
299309
self.values = new_value
300310

301311
def value_str(self, index=0):

0 commit comments

Comments
 (0)