Skip to content

Commit c35eb96

Browse files
committed
Streamline documentation style (#3232)
Adopt the Google docstrings style as the preferred way to document code. Update one of the existing docstrings to the new format, to showcase how it would look like. Enable the `napoleon` preprocessor in Sphinx, to be able to process Google style docstrings. Take the opportunity to make the copyright year dynamic, so we don't have to manually keep it up to date. --------- Co-authored-by: Gabriel Erzse <[email protected]>
1 parent 55bf558 commit c35eb96

File tree

3 files changed

+60
-63
lines changed

3 files changed

+60
-63
lines changed

.github/wordlist.txt

+2
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ bysource
7474
charset
7575
del
7676
dev
77+
docstring
78+
docstrings
7779
eg
7880
exc
7981
firsttimersonly

docs/conf.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
# All configuration values have a default; values that are commented out
1111
# serve to show the default.
1212

13+
import datetime
1314
import os
1415
import sys
1516

@@ -30,19 +31,23 @@
3031
"nbsphinx",
3132
"sphinx_gallery.load_style",
3233
"sphinx.ext.autodoc",
33-
"sphinx_autodoc_typehints",
34-
"sphinx.ext.doctest",
3534
"sphinx.ext.viewcode",
3635
"sphinx.ext.autosectionlabel",
36+
"sphinx.ext.napoleon",
3737
]
3838

39+
# Napoleon settings. We only accept Google-style docstrings.
40+
napoleon_google_docstring = True
41+
napoleon_numpy_docstring = False
42+
3943
# AutosectionLabel settings.
4044
# Uses a <page>:<label> schema which doesn't work for duplicate sub-section
4145
# labels, so set max depth.
4246
autosectionlabel_prefix_document = True
4347
autosectionlabel_maxdepth = 2
4448

4549
# AutodocTypehints settings.
50+
autodoc_typehints = 'description'
4651
always_document_param_types = True
4752
typehints_defaults = "comma"
4853

@@ -60,7 +65,8 @@
6065

6166
# General information about the project.
6267
project = "redis-py"
63-
copyright = "2023, Redis Inc"
68+
current_year = datetime.datetime.now().year
69+
copyright = f"{current_year}, Redis Inc"
6470

6571
# The version info for the project you're documenting, acts as replacement for
6672
# |version| and |release|, also used in various other places throughout the

redis/commands/core.py

+49-60
Original file line numberDiff line numberDiff line change
@@ -201,69 +201,58 @@ def acl_setuser(
201201
"""
202202
Create or update an ACL user.
203203
204-
Create or update the ACL for ``username``. If the user already exists,
204+
Create or update the ACL for `username`. If the user already exists,
205205
the existing ACL is completely overwritten and replaced with the
206206
specified values.
207207
208-
``enabled`` is a boolean indicating whether the user should be allowed
209-
to authenticate or not. Defaults to ``False``.
210-
211-
``nopass`` is a boolean indicating whether the can authenticate without
212-
a password. This cannot be True if ``passwords`` are also specified.
213-
214-
``passwords`` if specified is a list of plain text passwords
215-
to add to or remove from the user. Each password must be prefixed with
216-
a '+' to add or a '-' to remove. For convenience, the value of
217-
``passwords`` can be a simple prefixed string when adding or
218-
removing a single password.
219-
220-
``hashed_passwords`` if specified is a list of SHA-256 hashed passwords
221-
to add to or remove from the user. Each hashed password must be
222-
prefixed with a '+' to add or a '-' to remove. For convenience,
223-
the value of ``hashed_passwords`` can be a simple prefixed string when
224-
adding or removing a single password.
225-
226-
``categories`` if specified is a list of strings representing category
227-
permissions. Each string must be prefixed with either a '+' to add the
228-
category permission or a '-' to remove the category permission.
229-
230-
``commands`` if specified is a list of strings representing command
231-
permissions. Each string must be prefixed with either a '+' to add the
232-
command permission or a '-' to remove the command permission.
233-
234-
``keys`` if specified is a list of key patterns to grant the user
235-
access to. Keys patterns allow '*' to support wildcard matching. For
236-
example, '*' grants access to all keys while 'cache:*' grants access
237-
to all keys that are prefixed with 'cache:'. ``keys`` should not be
238-
prefixed with a '~'.
239-
240-
``reset`` is a boolean indicating whether the user should be fully
241-
reset prior to applying the new ACL. Setting this to True will
242-
remove all existing passwords, flags and privileges from the user and
243-
then apply the specified rules. If this is False, the user's existing
244-
passwords, flags and privileges will be kept and any new specified
245-
rules will be applied on top.
246-
247-
``reset_keys`` is a boolean indicating whether the user's key
248-
permissions should be reset prior to applying any new key permissions
249-
specified in ``keys``. If this is False, the user's existing
250-
key permissions will be kept and any new specified key permissions
251-
will be applied on top.
252-
253-
``reset_channels`` is a boolean indicating whether the user's channel
254-
permissions should be reset prior to applying any new channel permissions
255-
specified in ``channels``.If this is False, the user's existing
256-
channel permissions will be kept and any new specified channel permissions
257-
will be applied on top.
258-
259-
``reset_passwords`` is a boolean indicating whether to remove all
260-
existing passwords and the 'nopass' flag from the user prior to
261-
applying any new passwords specified in 'passwords' or
262-
'hashed_passwords'. If this is False, the user's existing passwords
263-
and 'nopass' status will be kept and any new specified passwords
264-
or hashed_passwords will be applied on top.
265-
266-
For more information see https://redis.io/commands/acl-setuser
208+
For more information, see https://redis.io/commands/acl-setuser
209+
210+
Args:
211+
username: The name of the user whose ACL is to be created or updated.
212+
enabled: Indicates whether the user should be allowed to authenticate.
213+
Defaults to `False`.
214+
nopass: Indicates whether the user can authenticate without a password.
215+
This cannot be `True` if `passwords` are also specified.
216+
passwords: A list of plain text passwords to add to or remove from the user.
217+
Each password must be prefixed with a '+' to add or a '-' to
218+
remove. For convenience, a single prefixed string can be used
219+
when adding or removing a single password.
220+
hashed_passwords: A list of SHA-256 hashed passwords to add to or remove
221+
from the user. Each hashed password must be prefixed with
222+
a '+' to add or a '-' to remove. For convenience, a single
223+
prefixed string can be used when adding or removing a
224+
single password.
225+
categories: A list of strings representing category permissions. Each string
226+
must be prefixed with either a '+' to add the category
227+
permission or a '-' to remove the category permission.
228+
commands: A list of strings representing command permissions. Each string
229+
must be prefixed with either a '+' to add the command permission
230+
or a '-' to remove the command permission.
231+
keys: A list of key patterns to grant the user access to. Key patterns allow
232+
'*' to support wildcard matching. For example, '*' grants access to
233+
all keys while 'cache:*' grants access to all keys that are prefixed
234+
with 'cache:'. `keys` should not be prefixed with a '~'.
235+
reset: Indicates whether the user should be fully reset prior to applying
236+
the new ACL. Setting this to `True` will remove all existing
237+
passwords, flags, and privileges from the user and then apply the
238+
specified rules. If `False`, the user's existing passwords, flags,
239+
and privileges will be kept and any new specified rules will be
240+
applied on top.
241+
reset_keys: Indicates whether the user's key permissions should be reset
242+
prior to applying any new key permissions specified in `keys`.
243+
If `False`, the user's existing key permissions will be kept and
244+
any new specified key permissions will be applied on top.
245+
reset_channels: Indicates whether the user's channel permissions should be
246+
reset prior to applying any new channel permissions
247+
specified in `channels`. If `False`, the user's existing
248+
channel permissions will be kept and any new specified
249+
channel permissions will be applied on top.
250+
reset_passwords: Indicates whether to remove all existing passwords and the
251+
`nopass` flag from the user prior to applying any new
252+
passwords specified in `passwords` or `hashed_passwords`.
253+
If `False`, the user's existing passwords and `nopass`
254+
status will be kept and any new specified passwords or
255+
hashed passwords will be applied on top.
267256
"""
268257
encoder = self.get_encoder()
269258
pieces: List[EncodableT] = [username]

0 commit comments

Comments
 (0)