Skip to content

Commit eca4d0b

Browse files
seveassigmavirus24
authored andcommitted
Display correct method signatures in documentation
Use an environment variable to make sphinx signal to github3 that it wants the actual signatures of functions and doesn't care about functionality. github3 in turn will use mock decorators instead of real ones so signatures do not get hidden.
1 parent b63015c commit eca4d0b

2 files changed

Lines changed: 12 additions & 28 deletions

File tree

docs/conf.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313

1414
import sys, os
1515

16+
# This environment variable makes decorators not decorate functions, so their
17+
# signatures in the generated documentation are still correct
18+
os.environ['GENERATING_DOCUMENTATION'] = "github3"
19+
1620
# If extensions (or modules to document with autodoc) are in another directory,
1721
# add these directories to sys.path here. If the directory is relative to the
1822
# documentation root, use os.path.abspath to make it absolute, like shown here.

github3/decorators.py

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from functools import wraps
1010
from requests.models import Response
11+
import os
1112

1213
try: # (No coverage)
1314
# python2
@@ -18,20 +19,7 @@
1819

1920

2021
def requires_auth(func):
21-
"""Decorator to note which object methods require authorization.
22-
23-
.. note::
24-
This decorator causes the wrapped methods to lose their proper
25-
signature. Please refer to the documentation for each of those.
26-
"""
27-
#note = """.. note::
28-
#The signature of this function may not appear correctly in
29-
#documentation. Please adhere to the defined parameters and their
30-
#types.
31-
#"""
32-
## Append the above note to each function this is applied to
33-
#func.__doc__ = '\n\n'.join([func.__doc__, note])
34-
22+
"""Decorator to note which object methods require authorization."""
3523
@wraps(func)
3624
def auth_wrapper(self, *args, **kwargs):
3725
auth = False
@@ -53,20 +41,7 @@ def auth_wrapper(self, *args, **kwargs):
5341

5442
def requires_basic_auth(func):
5543
"""Decorator to note which object methods require username/password
56-
authorization and won't work with token based authorization.
57-
58-
.. note::
59-
This decorator causes the wrapped methods to lose their proper
60-
signature. Please refer to the documentation for each of those.
61-
"""
62-
#note = """.. note::
63-
#The signature of this function may not appear correctly in
64-
#documentation. Please adhere to the defined parameters and their
65-
#types.
66-
#"""
67-
## Append the above note to each function this is applied to
68-
#func.__doc__ = '\n\n'.join([func.__doc__, note])
69-
44+
authorization and won't work with token based authorization."""
7045
@wraps(func)
7146
def auth_wrapper(self, *args, **kwargs):
7247
if hasattr(self, '_session') and self._session.auth:
@@ -80,3 +55,8 @@ def auth_wrapper(self, *args, **kwargs):
8055
r.raw = StringIO('{"message": "Requires username/password authentication"}'.encode())
8156
raise GitHubError(r)
8257
return auth_wrapper
58+
59+
# Use mock decorators when generating documentation, so all functino signatures
60+
# are displayed correctly
61+
if os.environ.get('GENERATING_DOCUMENTATION', None) == 'github3':
62+
requires_auth = requires_basic_auth = lambda x: x

0 commit comments

Comments
 (0)