Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/flying-sheep/legacy-api-wrap
Wrap legacy APIs in python projects
https://github.com/flying-sheep/legacy-api-wrap
api depreciation
Last synced: about 1 month ago
JSON representation
Wrap legacy APIs in python projects
- Host: GitHub
- URL: https://github.com/flying-sheep/legacy-api-wrap
- Owner: flying-sheep
- License: gpl-3.0
- Created: 2018-11-26T15:25:32.000Z (about 6 years ago)
- Default Branch: main
- Last Pushed: 2024-11-11T18:31:28.000Z (about 1 month ago)
- Last Synced: 2024-11-11T19:33:10.290Z (about 1 month ago)
- Topics: api, depreciation
- Language: Python
- Size: 79.1 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
Legacy API Wrapper |b-pypi| |b-codecov|
=======================================.. |b-pypi| image:: https://img.shields.io/pypi/v/legacy-api-wrap.svg
:target: https://pypi.org/project/legacy-api-wrap
.. |b-codecov| image:: https://codecov.io/gh/flying-sheep/legacy-api-wrap/graph/badge.svg
:target: https://codecov.io/gh/flying-sheep/legacy-api-wrapThis 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, eWe 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, eAfter adding the decorator, users can keep calling the old API and get a
``DeprecationWarning``:>>> fn(12, 13, 14) == (2, 14, 3)
True