I am trying to deprecate property of class.
JavaScript
x
7
1
class A:
2
def __init__(self,
3
variable1: int,
4
##to be deprecated
5
variable2: int )
6
{ .}
7
Expected behaviour: If user tries to use variable 2 he should get warning that its deprecated.
Advertisement
Answer
You can implement variable2
as a property.
JavaScript
1
17
17
1
import warnings
2
3
class A:
4
def __init__(self, variable1: int, variable2: int):
5
self.variable1 = variable1
6
self._variable2 = variable2
7
8
@property
9
def variable2(self):
10
warnings.warn('The use of variable2 is deprecated.', DeprecationWarning)
11
return self._variable2
12
13
@variable2.setter
14
def variable2(self, value: int):
15
warnings.warn('The use of variable2 is deprecated.', DeprecationWarning)
16
self._variable2 = value
17