Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make all the docstrings PEP 257 compliant #2028

Merged
merged 69 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
469750e
Updates to satsify pep257 violations
radez Apr 3, 2024
ba13137
🧪🔥 Drop separate pep257 linting check
webknjaz May 21, 2024
f076a71
Rewrite compat dopcstrings
webknjaz May 22, 2024
e30d3ee
Make dispatch module docstrings more accurate
webknjaz May 22, 2024
0295e06
Drop a redundand `pass` node from the error module
webknjaz May 22, 2024
208880d
Format the closing jdocstring quotes in dispatch mod
webknjaz May 22, 2024
c8ade18
Rephrase a function docstring in dispatch
webknjaz May 22, 2024
980af9b
Fix the spelling of CherryPy in logging mod
webknjaz May 22, 2024
8373831
Normalize the http error mod docstrings
webknjaz May 22, 2024
fe8867d
Improve the look of the logging module docstrings
webknjaz May 22, 2024
368a913
Improcve the `mod_python` integration docstrings
webknjaz May 22, 2024
e04421e
Improve docstrings for request body handler
webknjaz May 22, 2024
dc9271d
Improve the docstrings in the request module
webknjaz May 22, 2024
73619fa
Split the long line in a docstring in request mod
webknjaz May 22, 2024
b681368
Improve docstrings in the tools module
webknjaz May 22, 2024
4418bb9
Update cherrypy/lib/auth_digest.py
radez May 23, 2024
c3421b4
Update cherrypy/lib/auth_digest.py
radez May 23, 2024
3d83e72
Update cherrypy/lib/auth_digest.py
radez May 23, 2024
f04daa0
Update cherrypy/lib/auth_digest.py
radez May 23, 2024
9eb06d7
Update cherrypy/lib/auth_digest.py
radez May 23, 2024
2c0688d
Update cherrypy/lib/auth_digest.py
radez May 23, 2024
6962e42
Clarify `MemoryCache` initializer docstring
webknjaz Jun 30, 2024
8182840
Clarify `cherrypy.lib.caching` docstring
webknjaz Jun 30, 2024
ea6e6c9
Clarify docstrings in `cherrypy.lib.covercp` module
webknjaz Jun 30, 2024
83f2735
Clarify docstrings in `cherrypy.lib.cpstats` module
webknjaz Jun 30, 2024
d8ece8b
Clarify docstrings in `cherrypy.lib.cptools` module
webknjaz Jun 30, 2024
8e184c9
Clarify docstrings in `cherrypy.lib.encoding` module
webknjaz Jun 30, 2024
342b01a
Clarify docstrings in `cherrypy.lib.gctools` module
webknjaz Jun 30, 2024
25a1bef
Clarify docstrings in `cherrypy.lib.httputil` module
webknjaz Jun 30, 2024
ae3e9df
Clarify docstrings in `cherrypy.lib.jsontools` module
webknjaz Jun 30, 2024
dde7887
Clarify docstrings in `cherrypy.lib.locking` module
webknjaz Jun 30, 2024
4dabb1b
Clarify docstrings in `cherrypy._cprequest` module
webknjaz Jun 30, 2024
b616cc1
Clarify docstrings in `cherrypy.lib.profiler` module
webknjaz Jun 30, 2024
af4f8a5
Clarify docstrings in `cherrypy.lib.reprconf` module
webknjaz Jul 1, 2024
b588aa5
Clarify docstrings in `cherrypy.lib.sessions` module
webknjaz Jul 1, 2024
c262c0e
Clarify docstrings in `cherrypy.process.plugins` module
webknjaz Jul 1, 2024
18d8f71
Clarify docstrings in `cherrypy.process.servers` module
webknjaz Jul 1, 2024
9a9c743
Clarify docstrings in `cherrypy.process.win32` module
webknjaz Jul 1, 2024
7ec3fd7
Clarify docstrings in `cherrypy.test` package
webknjaz Jul 1, 2024
c0d3e28
fixup! cherrypy/test/__init__.py
webknjaz Jul 1, 2024
b68ca43
fixup! cherrypy/lib/sessions.py
webknjaz Jul 1, 2024
1285fa4
Clarify docstrings in `cherrypy.tutorial` package
webknjaz Jul 1, 2024
5a12861
Clarify docstrings in `cherrypy.test.webtest` module
webknjaz Jul 1, 2024
bab8974
fixup! cherrypy/test/webtest.py
webknjaz Jul 1, 2024
d0c0d6d
Clarify docstrings in `cherrypy.tutorial.tut01_helloworld` module
webknjaz Jul 1, 2024
cca0410
Clarify docstrings in `cherrypy.tutorial.tut03_get_and_post` module
webknjaz Jul 1, 2024
c0cff17
Clarify docstrings in `cherrypy.tutorial.tut02_expose_methods` module
webknjaz Jul 1, 2024
4244c61
Clarify docstrings in `cherrypy.tutorial.tut04_complex_site` module
webknjaz Jul 1, 2024
4dfd6f9
Clarify docstrings in `cherrypy.tutorial.tut05_derived_objects` module
webknjaz Jul 1, 2024
7deb828
Clarify docstrings in `cherrypy.tutorial.tut06_default_method` module
webknjaz Jul 1, 2024
3a20d16
Clarify docstrings in `cherrypy.tutorial.tut07_sessions` module
webknjaz Jul 1, 2024
e1bf5b8
Clarify docstrings in `cherrypy.tutorial.tut08_generators_and_yield` …
webknjaz Jul 1, 2024
9305612
Clarify docstrings in `cherrypy.tutorial.tut09_files` module
webknjaz Jul 1, 2024
6f9436d
Clarify docstrings in `cherrypy.tutorial.tut10_http_errors` module
webknjaz Jul 1, 2024
2da3f53
Clarify docstrings in `cherrypy.test.modwsgi` module
webknjaz Jul 1, 2024
0242ec4
Clarify docstrings in `cherrypy.test.sessiondemo` module
webknjaz Jul 1, 2024
c4f3906
Clarify docstrings in `cherrypy.test.modpy` module
webknjaz Jul 2, 2024
8a7d37d
Clarify docstrings in `cherrypy.test.modfcgid` module
webknjaz Jul 2, 2024
d90ca1d
Clarify docstrings in `cherrypy.test.modfastcgi` module
webknjaz Jul 2, 2024
43b172c
Clarify docstrings in `cherrypy.test.logtest` module
webknjaz Jul 2, 2024
4a82cbb
Clarify docstrings in `cherrypy.test.checkerdemo` module
webknjaz Jul 2, 2024
19528b1
Clarify docstrings in `cherrypy.test.helper` module
webknjaz Jul 2, 2024
2b1280a
Clarify docstrings in `cherrypy.test.benchmark` module
webknjaz Jul 2, 2024
5ea0c97
Clarify docstrings in `cherrypy.test._test_decorators` module
webknjaz Jul 2, 2024
248331e
Clarify docstrings in `cherrypy.test._test_states_demo` module
webknjaz Jul 2, 2024
71951cb
Clarify docstrings in `cherrypy.lib.auth_digest` module
webknjaz Jul 2, 2024
98175fb
Clarify docstrings in `cherrypy._cpwsgi` module
webknjaz Jul 2, 2024
b0b70a9
fixup! cherrypy/_cpwsgi.py
webknjaz Jul 2, 2024
a234f69
Clarify docstrings in `cherrypy.lib.headers` module
webknjaz Jul 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,6 @@ jobs:
# - linkcheck-docs
# - metadata-validation
- pre-commit
- pre-commit-pep257
- setup-check
# - spellcheck-docs
fail-fast: false
Expand All @@ -574,7 +573,7 @@ jobs:
- name: Grab the source from Git
if: >-
contains(
fromJSON('["pre-commit", "pre-commit-pep257", "spellcheck-docs"]'),
fromJSON('["pre-commit", "spellcheck-docs"]'),
matrix.toxenv
)
uses: actions/checkout@v3
Expand All @@ -583,7 +582,7 @@ jobs:
- name: Retrieve the project source from an sdist inside the GHA artifact
if: >-
!contains(
fromJSON('["pre-commit", "pre-commit-pep257", "spellcheck-docs"]'),
fromJSON('["pre-commit", "spellcheck-docs"]'),
matrix.toxenv
)
uses: re-actors/checkout-python-sdist@release/v1
Expand Down
9 changes: 0 additions & 9 deletions .pre-commit-config-pep257.yaml

This file was deleted.

17 changes: 0 additions & 17 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,6 @@ repos:
rev: 6.3.0
hooks:
- id: pydocstyle
exclude: |
(?x)
tests/dist|
cherrypy/(
_cp(
compat|modpy|logging|error|wsgi|dispatch|tools|reqbody|request
)|
(
lib/(
auth|auth_basic|auth_digest|caching|covercp|
cpstats|cptools|encoding|gctools|httpauth|httputil|
jsontools|lockfile|locking|profiler|reprconf|sessions
)|
process/(plugins|servers|win32)
).py|
test|tutorial
)

- repo: https://github.com/Lucas-C/pre-commit-hooks.git
rev: v1.5.4
Expand Down
11 changes: 7 additions & 4 deletions cherrypy/_cpcompat.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,19 @@


def ntob(n, encoding='ISO-8859-1'):
"""Return the given native string as a byte string in the given
encoding.
"""Convert a native :class:`str` to a :class:`bytes` instance.

The encoding can be changed to non-ASCII optionally.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment implies that the default encoding is ASCII, but it is not. It's latin-1 aka ISO-8859-1.

"""
assert_native(n)
# In Python 3, the native string type is unicode
return n.encode(encoding)


def ntou(n, encoding='ISO-8859-1'):
"""Return the given native string as a unicode string with the given
encoding.
"""Convert a native :class:`str` to a :class:`str` instance.

This doesn't actually do anything.
Comment on lines +35 to +37
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure we want to lose the context around the intended purpose of this function. If someone came to this docstring before the change, they could pretty easily infer what the purpose of this function was on Python 2. Following the change, it looks like this function never intended to do anything, so that context is lost.

"""
assert_native(n)
# In Python 3, the native string type is unicode
Expand All @@ -48,6 +50,7 @@ def tonative(n, encoding='ISO-8859-1'):


def assert_native(n):
"""Ensure that input is a native :class:`str`."""
if not isinstance(n, str):
raise TypeError('n must be a native str (got %s)' % type(n).__name__)

Expand Down
26 changes: 23 additions & 3 deletions cherrypy/_cpdispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class PageHandler(object):
"""Callable which sets response.body."""

def __init__(self, callable, *args, **kwargs):
"""Initialize the page handler."""
self.callable = callable
self.args = args
self.kwargs = kwargs
Expand All @@ -36,6 +37,7 @@ def args(self):

@args.setter
def args(self, args):
"""Set the request arguments in order."""
cherrypy.serving.request.args = args
return cherrypy.serving.request.args

Expand All @@ -46,10 +48,12 @@ def kwargs(self):

@kwargs.setter
def kwargs(self, kwargs):
"""Set the named request keyword arguments as :class:`dict`."""
cherrypy.serving.request.kwargs = kwargs
return cherrypy.serving.request.kwargs

def __call__(self):
"""Invoke an HTTP handler callable for :class:`PageHandler`."""
try:
return self.callable(*self.args, **self.kwargs)
except TypeError:
Expand Down Expand Up @@ -203,15 +207,18 @@ def test_callable_spec(callable, callable_args, callable_kwargs):
import inspect
except ImportError:
def test_callable_spec(callable, args, kwargs): # noqa: F811
"""Do nothing as a no-op."""
return None
else:
def getargspec(callable):
"""Get argument specification using :mod:`inspect`."""
return inspect.getfullargspec(callable)[:4]


class LateParamPageHandler(PageHandler):
"""Page handler callable with delayed request parameters binding.

"""When passing cherrypy.request.params to the page handler, we do not
When passing ``cherrypy.request.params`` to the page handler, we do not
want to capture that dict too early; we want to give tools like the
decoding tool a chance to modify the params dict in-between the lookup
of the handler and the actual calling of the handler. This subclass
Expand All @@ -221,14 +228,19 @@ class LateParamPageHandler(PageHandler):

@property
def kwargs(self):
"""Page handler kwargs (with cherrypy.request.params copied in)."""
"""Page handler keyword arguments.

The returned value contains data merged in
from ``cherrypy.request.params``.
"""
kwargs = cherrypy.serving.request.params.copy()
if self._kwargs:
kwargs.update(self._kwargs)
return kwargs

@kwargs.setter
def kwargs(self, kwargs):
"""Set the named request keyword arguments as :class:`dict`."""
cherrypy.serving.request.kwargs = kwargs
self._kwargs = kwargs

Expand All @@ -238,6 +250,7 @@ def kwargs(self, kwargs):
string.punctuation, '_' * len(string.punctuation))

def validate_translator(t):
"""Ensure the translator is of the correct length and size."""
if not isinstance(t, str) or len(t) != 256:
raise ValueError(
'The translate argument must be a str of len 256.')
Expand All @@ -246,6 +259,7 @@ def validate_translator(t):
string.punctuation, '_' * len(string.punctuation))

def validate_translator(t):
"""Ensure the translator is of the correct length and size."""
if not isinstance(t, dict):
raise ValueError('The translate argument must be a dict.')

Expand Down Expand Up @@ -273,6 +287,7 @@ class Dispatcher(object):

def __init__(self, dispatch_method_name=None,
translate=punctuation_to_underscores):
"""Initialize the HTTP request dispatcher."""
validate_translator(translate)
self.translate = translate
if dispatch_method_name:
Expand Down Expand Up @@ -389,7 +404,9 @@ def find_handler(self, path):
object_trail.append([name, node, nodeconf, segleft])

def set_conf():
"""Collapse all object_trail config into cherrypy.request.config.
"""Collapse all ``object_trail`` conf into config.

The config being ``cherrypy.request.config``.
"""
base = cherrypy.config.copy()
# Note that we merge the config from each node
Expand Down Expand Up @@ -505,10 +522,12 @@ def __init__(self, full_result=False, **mapper_options):
self.mapper.controller_scan = self.controllers.keys

def connect(self, name, route, controller, **kwargs):
"""Mount an HTTP handler into the router."""
self.controllers[name] = controller
self.mapper.connect(name, route, controller=name, **kwargs)

def redirect(self, url):
"""Perform an HTTP redirect to the given URL."""
raise cherrypy.HTTPRedirect(url)

def __call__(self, path_info):
Expand Down Expand Up @@ -602,6 +621,7 @@ def merge(nodeconf):


def XMLRPCDispatcher(next_dispatcher=Dispatcher()):
"""Chain an HTTP dispatcher variant implementing XML-RPC."""
from cherrypy.lib import xmlrpcutil

def xmlrpc_dispatch(path_info):
Expand Down
21 changes: 14 additions & 7 deletions cherrypy/_cperror.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ class Root:

class CherryPyException(Exception):
"""A base class for CherryPy exceptions."""
pass


class InternalRedirect(CherryPyException):
Expand All @@ -150,6 +149,7 @@ class InternalRedirect(CherryPyException):
"""

def __init__(self, path, query_string=''):
"""Initialize the internal redirect exception."""
self.request = cherrypy.serving.request

self.query_string = query_string
Expand Down Expand Up @@ -202,6 +202,7 @@ class HTTPRedirect(CherryPyException):
"""The encoding when passed urls are not native strings."""

def __init__(self, urls, status=None, encoding=None):
"""Initialize the HTTP redirect exception."""
self.urls = abs_urls = [
# Note that urljoin will "do the right thing" whether url is:
# 1. a complete URL with host (e.g. "http://www.example.com/test")
Expand All @@ -227,7 +228,9 @@ def __init__(self, urls, status=None, encoding=None):

@classproperty
def default_status(cls):
"""The default redirect status for the request.
"""Redirect status for the request.

This is the default handler.

RFC 2616 indicates a 301 response code fits our goal; however,
browser support for 301 is quite messy. Use 302/303 instead. See
Expand All @@ -242,8 +245,9 @@ def status(self):
return status

def set_response(self):
"""Modify cherrypy.response status, headers, and body to represent
self.
"""Modify ``cherrypy.response`` to represent ``self``.

Modifies status, headers, and body.

CherryPy uses this internally, but you can also use it to create
an HTTPRedirect object and set its output without *raising* the
Expand Down Expand Up @@ -366,6 +370,7 @@ class HTTPError(CherryPyException):
"""The HTTP Reason-Phrase string."""

def __init__(self, status=500, message=None):
"""Initialize an HTTP error."""
self.status = status
try:
self.code, self.reason, defaultmsg = _httputil.valid_status(status)
Expand All @@ -381,8 +386,9 @@ def __init__(self, status=500, message=None):
CherryPyException.__init__(self, status, message)

def set_response(self):
"""Modify cherrypy.response status, headers, and body to represent
self.
"""Modify ``cherrypy.response`` to represent ``self``.

Modifies status, headers, and body.

CherryPy uses this internally, but you can also use it to create
an HTTPError object and set its output without *raising* the
Expand All @@ -408,6 +414,7 @@ def set_response(self):
_be_ie_unfriendly(self.code)

def get_error_page(self, *args, **kwargs):
"""Compose an HTML page with error information."""
return get_error_page(*args, **kwargs)

def __call__(self):
Expand All @@ -432,6 +439,7 @@ class NotFound(HTTPError):
"""

def __init__(self, path=None):
"""Initialize an HTTP Not Found error."""
if path is None:
request = cherrypy.serving.request
path = request.script_name + request.path_info
Expand Down Expand Up @@ -600,7 +608,6 @@ def bare_error(extrabody=None):
is set in the body. If extrabody is a string, it will be appended
as-is to the body.
"""

# The whole point of this function is to be a last line-of-defense
# in handling errors. That is, it must not raise any errors itself;
# it cannot be allowed to fail. Therefore, don't add to it!
Expand Down
17 changes: 14 additions & 3 deletions cherrypy/_cplogging.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""
CherryPy logging module.

Simple config
=============

Expand Down Expand Up @@ -126,12 +128,15 @@ class NullHandler(logging.Handler):
"""A no-op logging handler to silence the logging.lastResort handler."""

def handle(self, record):
"""Handle a log record doing no-op."""
pass

def emit(self, record):
"""Emit a log record doing no-op."""
pass

def createLock(self):
"""Lock log write with no-op."""
self.lock = None


Expand Down Expand Up @@ -167,6 +172,7 @@ class LogManager(object):
"""

def __init__(self, appid=None, logger_root='cherrypy'):
"""Initialize a CherryPy log manager."""
self.logger_root = logger_root
self.appid = appid
if appid is None:
Expand Down Expand Up @@ -217,11 +223,11 @@ def error(self, msg='', context='', severity=logging.INFO,
)

def __call__(self, *args, **kwargs):
"""An alias for ``error``."""
"""Record an error log entry."""
return self.error(*args, **kwargs)

def access(self):
"""Write to the access log (in Apache/NCSA Combined Log format).
r"""Write to the access log (in Apache/NCSA Combined Log format).

See the
`apache documentation
Expand Down Expand Up @@ -414,7 +420,10 @@ def wsgi(self, newvalue):


class WSGIErrorHandler(logging.Handler):
"A handler class which writes logging records to environ['wsgi.errors']."
"""A handler class writing logs to WSGI env.

Specifically, the target is ``environ['wsgi.errors']``.
"""

def flush(self):
"""Flushes the stream."""
Expand Down Expand Up @@ -450,6 +459,8 @@ def emit(self, record):


class LazyRfc3339UtcTime(object):
"""A postponed timestamp string retrieval class."""

def __str__(self):
"""Return datetime in RFC3339 UTC Format."""
iso_formatted_now = datetime.datetime.now(
Expand Down
Loading
Loading