Skip to content

Commit abde151

Browse files
decorators for adding api status to class/function docs
1 parent 11167ca commit abde151

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

PYME/apistatus.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
"""
2+
3+
This module defines a series of decorators used for documenting functions API status / maturity. The hope is that this
4+
will provide a simple way of indicating which parts of PYME are safe to use from third party code (and which parts are
5+
volatile).
6+
7+
"""
8+
9+
10+
def _api_annotation(status_blurb):
11+
def dec(obj):
12+
"""Decorator to mark the API status of a function/class
13+
14+
Parameters
15+
----------
16+
obj : object to be decorated
17+
18+
"""
19+
20+
obj.__doc__ = obj.__doc__ + '\nAPI Status\n-----------\n' + status_blurb
21+
22+
return obj
23+
24+
return dec
25+
26+
api = _api_annotation('''
27+
**API:** This is considered part of the external API and expected to be used 3rd party code. Any backwards incompatible
28+
future changes will by clearly signalled with deprecation warnings for several releases prior to making breaking changes.
29+
''')
30+
31+
internal = _api_annotation('''
32+
**Internal:** This is not expected to be called from 3rd party code and may change without notice, use at you own risk.
33+
''')
34+
35+
experimental = _api_annotation('''
36+
**Experimental:** This is experimental functionality, or functionality under development. It might become part of the API
37+
in the future, but for now expect some volatility. If you want to use this functionality please get in touch - you might
38+
even be able to help shape the interface to best suit your usage.
39+
''')
40+
41+
dirty_api = _api_annotation('''
42+
**Dirty API:** This really should be API, but is also in need of refactoring as the current interface is gross, broken,
43+
or inconsistent. Guarantees here are weaker than for the API class, but we will endeavour to ensure that a) equivalent
44+
functionality is available after refactoring an b) breaking changes give rise to error messages that point to information
45+
on the new usage.
46+
''')
47+
48+
removal_candidate = _api_annotation('''
49+
***Removal candidate:** This code is likely to disappear, potentially without warning. It has either been replaced with
50+
a better alternative, or is old, legacy code which is hard to justify maintaining.
51+
''')

0 commit comments

Comments
 (0)