[Tutor] refractoing and backward-compatibility
Steven D'Aprano
steve at pearwood.info
Tue Sep 7 13:27:54 CEST 2010
On Tue, 7 Sep 2010 08:07:11 pm Timmie wrote:
> Hello,
> I would like to refractor a module I write adding more functiosn and
> renaming old ones.
>
> In order to maintain backward compatibility with old scripts that
> reply on those modules, I would like to introduce alias names for the
> old functions:
[...]
> Is this a good approach or are there better suggestions out there in
> the Python community for such a purpose?
Sounds fine to me, although some people might disagree.
Using aliases in this way is probably best when you only have one or two
aliases, rather than dozens.
Another approach is to have a compatibility module -- have one module
with the functionality, and a second module with aliases. The second
module could be simply:
from module import old as new, ham as spam, bill as william
which creates aliases:
"new" instead of "old"
"spam" instead of "ham"
"william" instead of "bill"
Then the caller can either say
import module
module.ham()
or
import other_module
other_module.spam()
--
Steven D'Aprano
More information about the Tutor
mailing list