Renaming of functions with preservation of backward compatibility

后端 未结 4 1605
轻奢々
轻奢々 2021-02-19 15:12

I refactor my old code and want to change the names of functions in accordance with pep8. But I want to maintain backward compatibility with old parts of system (a complete refa

4条回答
  •  轮回少年
    2021-02-19 15:32

    While the other answers are definitely true, it could be useful to rename the function to the new name and create an old one which emits a warning:

    def func_new(a):
        do_stuff()
    
    def funcOld(a):
        import warnings
        warnings.warn("funcOld should not be called any longer.")
        return func_new(a)
    

提交回复
热议问题