Zope Deprecation Infrastructure

6.0 · active · verified Fri Apr 10

zope.deprecation provides utilities for marking modules, classes, functions, methods, and properties as deprecated in Python projects. It helps manage backward compatibility by issuing warnings when deprecated code is used. The current version is 6.0, and it generally sees a few releases per year, often tied to Python version support updates or internal Zope Foundation infrastructure changes.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use the `@deprecate` decorator for functions and mentions `moved` for module relocations. It also shows how to enable warnings and temporarily suppress them using `Suppressor`.

from zope.deprecation import deprecate, moved
import warnings

# Deprecating a function
@deprecate('Use new_function instead of old_function.')
def old_function():
    return "This is an old function."

# Deprecating a module that has moved
# In old_module.py (assuming it was moved to new_package.new_module)
# This would be placed in the *original* location of the module:
# from zope.deprecation import moved
# moved("new_package.new_module", "2.0")

# Example usage with warnings enabled
warnings.simplefilter('always')

print(old_function()) # This will emit a DeprecationWarning

# You can also suppress warnings for specific blocks
with Suppressor():
    print(old_function()) # No warning will be emitted here

view raw JSON →