I have inherited the maintenance on some API code. One of the things I need to update is some environment information (think staging, production). The old names were test
and production
, while the new names are sandbox
, simulator
and production
. The old name test
has the same semantics as simulator
today.
How this was implemented is using a class, with class instances predefined for each environment, something like:
class Environment(object):
def __init__(self, name, params):
self.name = name
self.params = params
Environment.Test = Environment('test', ... params ...)
Environment.Production = Environment('production', ... params ...)
I can easily define the new names, and do something like
Environment.Test = Environment.Simulator
so existing code doesn’t break. But I’d like to have code which uses this raise a Python deprecation warning.
How can I do it? I can hack it by inserting an if
inside the class code and raise a deprecation warning there, but is there a cleaner way?