Reputation: 1
I have a class 'Model' in a.py, Now the class has moved to b.py. So whenever end user use from a import Model, I wanted to through an deprecation or some warning message. Any idea how to do that?
Upvotes: 0
Views: 179
Reputation: 431
I came up with this simple solution :
class Model:
def __init__(self):
# prints a warning message in the console
print('The "Model" class has been moved to b.py, please consider modifying your code !')
m = Model() # instantiate the model class to throw the message
This should work like you expected it Edit: this is the code for a.py
Upvotes: 0
Reputation: 427
you should use warning (https://docs.python.org/3/library/warnings.html) and more specially DeprecationWarning (https://docs.python.org/3/library/exceptions.html#DeprecationWarning)
a good answer already exist here : How to warn about class (name) deprecation
Upvotes: 1