Skip to content

Commit c146017

Browse files
authored
PYTHON-4012 Adopt more RST static checks (#1412)
1 parent 8faa910 commit c146017

12 files changed

+138
-124
lines changed

.pre-commit-config.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,20 @@ repos:
3838
additional_dependencies:
3939
- black==22.3.0
4040

41+
- repo: https://github.com/pre-commit/pygrep-hooks
42+
rev: "v1.10.0"
43+
hooks:
44+
- id: rst-backticks
45+
- id: rst-directive-colons
46+
- id: rst-inline-touching-normal
47+
48+
- repo: https://github.com/rstcheck/rstcheck
49+
rev: v6.2.0
50+
hooks:
51+
- id: rstcheck
52+
additional_dependencies: [sphinx]
53+
args: ["--ignore-directives=doctest,testsetup,todo,automodule","--ignore-substitutions=release", "--report-level=error"]
54+
4155
# We use the Python version instead of the original version which seems to require Docker
4256
# https://github.com/koalaman/shellcheck-precommit
4357
- repo: https://github.com/shellcheck-py/shellcheck-py

CONTRIBUTING.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ To run ``pre-commit`` manually, run::
115115

116116
pre-commit run --all-files
117117

118-
To run a manual hook like `flake8` manually, run::
118+
To run a manual hook like ``flake8`` manually, run::
119119

120120
pre-commit run --all-files --hook-stage manual flake8
121121

doc/changelog.rst

Lines changed: 97 additions & 97 deletions
Large diffs are not rendered by default.

doc/developer/periodic_executor.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Periodic Executors
55

66
PyMongo implements a :class:`~periodic_executor.PeriodicExecutor` for two
77
purposes: as the background thread for :class:`~monitor.Monitor`, and to
8-
regularly check if there are `OP_KILL_CURSORS` messages that must be sent to the server.
8+
regularly check if there are ``OP_KILL_CURSORS`` messages that must be sent to the server.
99

1010
Killing Cursors
1111
---------------
@@ -17,7 +17,7 @@ the cursor before finishing iteration::
1717
for doc in collection.find():
1818
raise Exception()
1919

20-
We try to send an `OP_KILL_CURSORS` to the server to tell it to clean up the
20+
We try to send an ``OP_KILL_CURSORS`` to the server to tell it to clean up the
2121
server-side cursor. But we must not take any locks directly from the cursor's
2222
destructor (see `PYTHON-799`_), so we cannot safely use the PyMongo data
2323
structures required to send a message. The solution is to add the cursor's id
@@ -26,7 +26,7 @@ to an array on the :class:`~mongo_client.MongoClient` without taking any locks.
2626
Each client has a :class:`~periodic_executor.PeriodicExecutor` devoted to
2727
checking the array for cursor ids. Any it sees are the result of cursors that
2828
were freed while the server-side cursor was still open. The executor can safely
29-
take the locks it needs in order to send the `OP_KILL_CURSORS` message.
29+
take the locks it needs in order to send the ``OP_KILL_CURSORS`` message.
3030

3131
.. _PYTHON-799: https://jira.mongodb.org/browse/PYTHON-799
3232

@@ -103,7 +103,7 @@ the exponential backoff is restarted frequently. Overall, the condition variable
103103
is not waking a few times a second, but hundreds of times. (See `PYTHON-983`_.)
104104

105105
Thus the current design of periodic executors is surprisingly simple: they
106-
do a simple `time.sleep` for a half-second, check if it is time to wake or
106+
do a simple ``time.sleep`` for a half-second, check if it is time to wake or
107107
terminate, and sleep again.
108108

109109
.. _Server Discovery And Monitoring Spec: https://github.com/mongodb/specifications/blob/master/source/server-discovery-and-monitoring/server-monitoring.rst#requesting-an-immediate-check

doc/examples/authentication.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ URI::
180180
>>> client = MongoClient(uri)
181181
>>>
182182

183-
The default service name used by MongoDB and PyMongo is `mongodb`. You can
183+
The default service name used by MongoDB and PyMongo is ``mongodb``. You can
184184
specify a custom service name with the ``authMechanismProperties`` option::
185185

186186
>>> from pymongo import MongoClient

doc/examples/datetimes.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ time. Avoid doing this:
3737

3838
>>> result = db.objects.insert_one({"last_modified": datetime.datetime.now()})
3939

40-
The value for `last_modified` is very different between these two examples, even
40+
The value for ``last_modified`` is very different between these two examples, even
4141
though both documents were stored at around the same local time. This will be
4242
confusing to the application that reads them:
4343

@@ -47,7 +47,7 @@ confusing to the application that reads them:
4747
[datetime.datetime(2015, 7, 8, 18, 17, 28, 324000),
4848
datetime.datetime(2015, 7, 8, 11, 17, 42, 911000)]
4949

50-
:class:`bson.codec_options.CodecOptions` has a `tz_aware` option that enables
50+
:class:`bson.codec_options.CodecOptions` has a ``tz_aware`` option that enables
5151
"aware" :class:`datetime.datetime` objects, i.e., datetimes that know what
5252
timezone they're in. By default, PyMongo retrieves naive datetimes:
5353

@@ -65,7 +65,7 @@ Saving Datetimes with Timezones
6565
-------------------------------
6666

6767
When storing :class:`datetime.datetime` objects that specify a timezone
68-
(i.e. they have a `tzinfo` property that isn't ``None``), PyMongo will convert
68+
(i.e. they have a ``tzinfo`` property that isn't ``None``), PyMongo will convert
6969
those datetimes to UTC automatically:
7070

7171
.. doctest::
@@ -82,12 +82,12 @@ Reading Time
8282

8383
As previously mentioned, by default all :class:`datetime.datetime` objects
8484
returned by PyMongo will be naive but reflect UTC (i.e. the time as stored in
85-
MongoDB). By setting the `tz_aware` option on
85+
MongoDB). By setting the ``tz_aware`` option on
8686
:class:`~bson.codec_options.CodecOptions`, :class:`datetime.datetime` objects
87-
will be timezone-aware and have a `tzinfo` property that reflects the UTC
87+
will be timezone-aware and have a ``tzinfo`` property that reflects the UTC
8888
timezone.
8989

90-
PyMongo 3.1 introduced a `tzinfo` property that can be set on
90+
PyMongo 3.1 introduced a ``tzinfo`` property that can be set on
9191
:class:`~bson.codec_options.CodecOptions` to convert :class:`datetime.datetime`
9292
objects to local time automatically. For example, if we wanted to read all times
9393
out of MongoDB in US/Pacific time:
@@ -159,7 +159,7 @@ cannot be represented using the builtin Python :class:`~datetime.datetime`:
159159
:attr:`~bson.datetime_ms.DatetimeConversion.DATETIME_CLAMP` will clamp
160160
resulting :class:`~datetime.datetime` objects to be within
161161
:attr:`~datetime.datetime.min` and :attr:`~datetime.datetime.max`
162-
(trimmed to `999000` microseconds):
162+
(trimmed to ``999000`` microseconds):
163163

164164
.. doctest::
165165

doc/examples/server_selection.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Server Selector Example
22
=======================
33

44
Users can exert fine-grained control over the `server selection algorithm`_
5-
by setting the `server_selector` option on the :class:`~pymongo.MongoClient`
5+
by setting the ``server_selector`` option on the :class:`~pymongo.MongoClient`
66
to an appropriate callable. This example shows how to use this functionality
77
to prefer servers running on ``localhost``.
88

doc/examples/timeouts.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ timeout for an :meth:`~pymongo.collection.Collection.insert_one` operation::
2323
coll.insert_one({"name": "Nunu"})
2424

2525
The :meth:`~pymongo.timeout` applies to all pymongo operations within the block.
26-
The following example ensures that both the `insert` and the `find` complete
26+
The following example ensures that both the ``insert`` and the ``find`` complete
2727
within 10 seconds total, or raise a timeout error::
2828

2929
with pymongo.timeout(10):

doc/examples/type_hints.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ These methods automatically add an "_id" field.
117117

118118
This same typing scheme works for all of the insert methods (:meth:`~pymongo.collection.Collection.insert_one`,
119119
:meth:`~pymongo.collection.Collection.insert_many`, and :meth:`~pymongo.collection.Collection.bulk_write`).
120-
For `bulk_write` both :class:`~pymongo.operations.InsertOne` and :class:`~pymongo.operations.ReplaceOne` operators are generic.
120+
For ``bulk_write`` both :class:`~pymongo.operations.InsertOne` and :class:`~pymongo.operations.ReplaceOne` operators are generic.
121121

122122
.. doctest::
123123
:pyversion: >= 3.8
@@ -139,16 +139,16 @@ Modeling Document Types with TypedDict
139139
--------------------------------------
140140

141141
You can use :py:class:`~typing.TypedDict` (Python 3.8+) to model structured data.
142-
As noted above, PyMongo will automatically add an `_id` field if it is not present. This also applies to TypedDict.
142+
As noted above, PyMongo will automatically add an ``_id`` field if it is not present. This also applies to TypedDict.
143143
There are three approaches to this:
144144

145-
1. Do not specify `_id` at all. It will be inserted automatically, and can be retrieved at run-time, but will yield a type-checking error unless explicitly ignored.
145+
1. Do not specify ``_id`` at all. It will be inserted automatically, and can be retrieved at run-time, but will yield a type-checking error unless explicitly ignored.
146146

147-
2. Specify `_id` explicitly. This will mean that every instance of your custom TypedDict class will have to pass a value for `_id`.
147+
2. Specify ``_id`` explicitly. This will mean that every instance of your custom TypedDict class will have to pass a value for ``_id``.
148148

149-
3. Make use of :py:class:`~typing.NotRequired`. This has the flexibility of option 1, but with the ability to access the `_id` field without causing a type-checking error.
149+
3. Make use of :py:class:`~typing.NotRequired`. This has the flexibility of option 1, but with the ability to access the ``_id`` field without causing a type-checking error.
150150

151-
Note: to use :py:class:`~typing.TypedDict` and :py:class:`~typing.NotRequired` in earlier versions of Python (<3.8, <3.11), use the `typing_extensions` package.
151+
Note: to use :py:class:`~typing.TypedDict` and :py:class:`~typing.NotRequired` in earlier versions of Python (<3.8, <3.11), use the ``typing_extensions`` package.
152152

153153
.. doctest:: typed-dict-example
154154
:pyversion: >= 3.11

doc/faq.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ drop below the minimum, more sockets are opened until the minimum is reached.
125125

126126
The maximum number of milliseconds that a connection can remain idle in the
127127
pool before being removed and replaced can be set with ``maxIdleTimeMS``, which
128-
defaults to `None` (no limit).
128+
defaults to ``None`` (no limit).
129129

130130
The default configuration for a :class:`~pymongo.mongo_client.MongoClient`
131131
works for most applications::
@@ -495,9 +495,9 @@ and :class:`~bson.dbref.DBRef`) that are not supported in JSON.
495495

496496
`python-bsonjs <https://pypi.python.org/pypi/python-bsonjs>`_ is a fast
497497
BSON to MongoDB Extended JSON converter built on top of
498-
`libbson <https://github.com/mongodb/libbson>`_. `python-bsonjs` does not
498+
`libbson <https://github.com/mongodb/libbson>`_. ``python-bsonjs`` does not
499499
depend on PyMongo and can offer a nice performance improvement over
500-
:mod:`~bson.json_util`. `python-bsonjs` works best with PyMongo when using
500+
:mod:`~bson.json_util`. ``python-bsonjs`` works best with PyMongo when using
501501
:class:`~bson.raw_bson.RawBSONDocument`.
502502

503503
Why do I get OverflowError decoding dates stored by another language's driver?
@@ -543,7 +543,7 @@ objects as before:
543543
For other options, please refer to
544544
:class:`~bson.codec_options.DatetimeConversion`.
545545

546-
Another option that does not involve setting `datetime_conversion` is to to
546+
Another option that does not involve setting ``datetime_conversion`` is to to
547547
filter out documents values outside of the range supported by
548548
:class:`~datetime.datetime`:
549549

doc/migrate-to-pymongo4.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,7 @@ GridFS changes
870870
disable_md5 parameter is removed
871871
................................
872872

873-
Removed the `disable_md5` option for :class:`~gridfs.GridFSBucket` and
873+
Removed the ``disable_md5`` option for :class:`~gridfs.GridFSBucket` and
874874
:class:`~gridfs.GridFS`. GridFS no longer generates checksums.
875875
Applications that desire a file digest should implement it outside GridFS
876876
and store it with other file metadata. For example::

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ description = build sphinx docs
133133
deps =
134134
-rdoc/docs-requirements.txt
135135
commands =
136-
sphinx-build -E -b html doc ./doc/_build/html
136+
sphinx-build -E -W -b html doc ./doc/_build/html
137137

138138
[testenv:doc-test]
139139
description = run sphinx doc tests

0 commit comments

Comments
 (0)