Skip to main content

Legacy API wrapper.

Project description

This module defines a decorator to wrap legacy APIs. The primary use case is APIs defined before keyword-only parameters existed.

>>> from legacy_api_wrap import legacy_api

We have a function with many positional parameters lying around:

>>> def fn(a, b=None, d=1, c=2):
...     return c, d, e

We want to convert the positional parameters d and c to keyword-only, change their order and add a parameter. For this we only need to specify name and order of the old positional parameters in the decorator.

>>> @legacy_api('d', 'c')
... def fn(a, b=None, *, c=2, d=1, e=3):
...     return c, d, e

After adding the decorator, users can keep calling the old API and get a DeprecationWarning:

>>> fn(12, 13, 14) == (2, 14, 3)

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for legacy-api-wrap, version 1.2
Filename, size File type Python version Upload date Hashes
Filename, size legacy_api_wrap-1.2-py3-none-any.whl (37.0 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size legacy-api-wrap-1.2.tar.gz (14.7 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page