deprecating parameters
Martin Pool
mbp at sourcefrog.net
Mon Jan 16 04:15:12 GMT 2006
On Sun, 2006-01-15 at 19:39 -0600, John Arbash Meinel wrote:
> Robert Collins wrote:
> > So, for symbol versioning in the branch-formats branch I needed to mark
> > Branch(..., init=XXX) as deprecated.
> >
> > I've used the follow for now:
> >
> > def __init__(self, transport, init=deprecated_nonce,
> > relax_version_check=False):
> > ....
> >
> > if deprecated_passed(init):
> > warn("BzrBranch.__init__(..., init=XXX): The init parameter
> > is "
> > "deprecated. Please use Branch.initialize().",
> > DeprecationWarning)
> >
> >
> > deprecated_nonce is a marker used by deprecated_passed - its assumed
> > noone will ever deliberately pass deprecated_none into a routine (and if
> > they do, their problem). (Its an object instance, theres no way to
> > accidentally do this).
> >
> >
> > I took this route because I was not sure how to make a -nice- parameter
> > deprecation decorator at this point - but I'm adding a TODO to research
> > that later.
> >
> > Does this sound reasonable to folk ?
> >
> > Rob
> >
>
> What do you consider to be a 'nice' parameter deprecation decorator.
> Because couldn't you do something like:
>
> @deprecated_parameter(3, 'init')
>
> And then inside the wrapper, you could check if 'args' is long enough to
> contain the deprecated parameter, or if 'kwargs' contains the keyword.
>
> Nicer, probably would be to just do:
> @deprecated_parameter('init')
Or perhaps
def foo(@deprecated init)
but I don't know if you can even attach decorators to parameters.
What Robert did looks quite reasonable to me.
I would perhaps call the magic value "DEPRECATED_PARAMETER" because:
- it's sufficiently special that it deserves not to look like a regular
identifier (perhaps it should be DeprecatedParameter)
- 'nonce' might be a bit strange for people who are not native english
speakers, and it's perhaps not used in the canonical technical sense of
a one-time random value, and it might be confused with None
--
Martin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20060116/4a743a31/attachment.pgp
More information about the bazaar
mailing list