Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commiteca4d0b

Browse files
seveassigmavirus24
authored andcommitted
Display correct method signatures in documentation
Use an environment variable to make sphinx signal to github3 that itwants the actual signatures of functions and doesn't care aboutfunctionality.github3 in turn will use mock decorators instead of real ones sosignatures do not get hidden.
1 parentb63015c commiteca4d0b

File tree

2 files changed

+12
-28
lines changed

2 files changed

+12
-28
lines changed

‎docs/conf.py

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

1414
importsys,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
fromfunctoolsimportwraps
1010
fromrequests.modelsimportResponse
11+
importos
1112

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

1920

2021
defrequires_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
defauth_wrapper(self,*args,**kwargs):
3725
auth=False
@@ -53,20 +41,7 @@ def auth_wrapper(self, *args, **kwargs):
5341

5442
defrequires_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
defauth_wrapper(self,*args,**kwargs):
7247
ifhasattr(self,'_session')andself._session.auth:
@@ -80,3 +55,8 @@ def auth_wrapper(self, *args, **kwargs):
8055
r.raw=StringIO('{"message": "Requires username/password authentication"}'.encode())
8156
raiseGitHubError(r)
8257
returnauth_wrapper
58+
59+
# Use mock decorators when generating documentation, so all functino signatures
60+
# are displayed correctly
61+
ifos.environ.get('GENERATING_DOCUMENTATION',None)=='github3':
62+
requires_auth=requires_basic_auth=lambdax:x

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp