Skip to content
Switch branches/tags
Go to file
Cannot retrieve contributors at this time
63 lines (35 sloc) 1.86 KB

Deprecation Best Prcatices

Why Deprecation

While refactoring code moving modules, functions, classes and methods is often needed. To not break third party code imports from the old place or usage of old functions or methods must work for while. Deprecated methods are usually removed with the next major release of Plone. Following the semantic versioning guideline is recommended.

Enable Deprecation Warnings

Using plone.recipe.zope2instance add the option deprecation-warnings = on to the buildouts [instance] section.

Vanilla Deprecation Messages

Python offers a built-in DeprecationWarning which can be issued using standard libraries warnings module.

For details read the official documentation.

In short it works like so

import warnings
warnings.warn('deprecated', DeprecationWarning)

Moving Whole Modules

Given a package old.pkg with a module need to be moved to a package new.pkg as

zope.deprecation offers a helper.

  1. Copy the as to the new.pkg.

  2. At the old place create a new and add to it

    from zope.deprecation import moved
    moved('', 'Version 2.0')

Now you can still import the namespace from bar at the old place, but get a deprecation warning:

DeprecationWarning: has moved to Import of will become unsupported in Version 2.0

Moving Whole Packages

This is the same as moving a module, just create for each module a file.