Skip to content

Commit d340710

Browse files
authored
PYTHON-3703 Fix typos and add codespell pre-commit hook (#1203)
Update pre-commit config adding "codespell" hook
1 parent 14e8b01 commit d340710

23 files changed

+73
-59
lines changed

.pre-commit-config.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,16 @@ repos:
8383
files: \.py$
8484
exclude: "^(test|tools)/"
8585
stages: [manual]
86+
87+
- repo: https://github.com/codespell-project/codespell
88+
rev: "v2.2.4"
89+
hooks:
90+
- id: codespell
91+
# Examples of errors or updates to justify the exceptions:
92+
# - test/test_on_demand_csfle.py:44: FLE ==> FILE
93+
# - test/test_bson.py:1043: fo ==> of, for, to, do, go
94+
# - test/bson_corpus/decimal128-4.json:98: Infinit ==> Infinite
95+
# - test/test_bson.py:267: isnt ==> isn't
96+
# - test/versioned-api/crud-api-version-1-strict.json:514: nin ==> inn, min, bin, nine
97+
# - test/test_client.py:188: te ==> the, be, we, to
98+
args: ["-L", "fle,fo,infinit,isnt,nin,te"]

bson/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1282,7 +1282,7 @@ def decode_file_iter(
12821282
# Read size of next object.
12831283
size_data = file_obj.read(4)
12841284
if not size_data:
1285-
break # Finished with file normaly.
1285+
break # Finished with file normally.
12861286
elif len(size_data) != 4:
12871287
raise InvalidBSON("cut off in middle of objsize")
12881288
obj_size = _UNPACK_INT_FROM(size_data, 0)[0] - 4

bson/_cbsonmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -968,7 +968,7 @@ static int _write_element_to_buffer(PyObject* self, buffer_t buffer,
968968
}
969969
}
970970

971-
/* No _type_marker attibute or not one of our types. */
971+
/* No _type_marker attribute or not one of our types. */
972972

973973
if (PyBool_Check(value)) {
974974
const char c = (value == Py_True) ? 0x01 : 0x00;

bson/objectid.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ def __getstate__(self) -> bytes:
231231

232232
def __setstate__(self, value: Any) -> None:
233233
"""explicit state set from pickling"""
234-
# Provide backwards compatability with OIDs
234+
# Provide backwards compatibility with OIDs
235235
# pickled with pymongo-1.9 or older.
236236
if isinstance(value, dict):
237237
oid = value["_ObjectId__id"]

bson/time64.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ static const Year years_in_gregorian_cycle = 400;
7373
#define days_in_gregorian_cycle ((365 * 400) + 100 - 4 + 1)
7474
static const Time64_T seconds_in_gregorian_cycle = days_in_gregorian_cycle * 60LL * 60LL * 24LL;
7575

76-
/* Year range we can trust the time funcitons with */
76+
/* Year range we can trust the time functions with */
7777
#define MAX_SAFE_YEAR 2037
7878
#define MIN_SAFE_YEAR 1971
7979

@@ -739,7 +739,7 @@ struct TM *cbson_localtime64_r (const Time64_T *time, struct TM *local_tm)
739739
/* GMT is Jan 1st, xx01 year, but localtime is still Dec 31st
740740
in a non-leap xx00. There is one point in the cycle
741741
we can't account for which the safe xx00 year is a leap
742-
year. So we need to correct for Dec 31st comming out as
742+
year. So we need to correct for Dec 31st coming out as
743743
the 366th day of the year.
744744
*/
745745
if( !IS_LEAP(local_tm->tm_year) && local_tm->tm_yday == 365 )

doc/changelog.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2805,7 +2805,7 @@ Important New Features:
28052805
- The URI parser has been moved into its own module and can be used directly
28062806
by application code.
28072807
- AutoReconnect exception now provides information about the error that
2808-
actually occured instead of a generic failure message.
2808+
actually occurred instead of a generic failure message.
28092809
- A number of new helper methods have been added with options for setting and
28102810
unsetting cursor flags, re-indexing a collection, fsync and locking a server,
28112811
and getting the server's current operations.
@@ -2930,7 +2930,7 @@ Issues resolved
29302930
- `PYTHON-186 <https://jira.mongodb.org/browse/PYTHON-186>`_:
29312931
When storing integers, type is selected according to value instead of type
29322932
- `PYTHON-173 <https://jira.mongodb.org/browse/PYTHON-173>`_:
2933-
as_class option is not propogated by Cursor.clone
2933+
as_class option is not propagated by Cursor.clone
29342934
- `PYTHON-113 <https://jira.mongodb.org/browse/PYTHON-113>`_:
29352935
Redunducy in MasterSlaveConnection
29362936

doc/contributors.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,4 @@ The following is a list of people who have contributed to
9393
- Ishmum Jawad Khan (ishmum123)
9494
- Arie Bovenberg (ariebovenberg)
9595
- Ben Warner (bcwarner)
96+
- Jean-Christophe Fillion-Robin (jcfr)

doc/examples/bulk.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ of operations performed.
8080

8181
The first write failure that occurs (e.g. duplicate key error) aborts the
8282
remaining operations, and PyMongo raises
83-
:class:`~pymongo.errors.BulkWriteError`. The :attr:`details` attibute of
83+
:class:`~pymongo.errors.BulkWriteError`. The :attr:`details` attribute of
8484
the exception instance provides the execution results up until the failure
8585
occurred and details about the failure - including the operation that caused
8686
the failure.

doc/examples/type_hints.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ Troubleshooting
264264

265265
Client Type Annotation
266266
~~~~~~~~~~~~~~~~~~~~~~
267-
If you forget to add a type annotation for a :class:`~pymongo.mongo_client.MongoClient` object you may get the followig ``mypy`` error::
267+
If you forget to add a type annotation for a :class:`~pymongo.mongo_client.MongoClient` object you may get the following ``mypy`` error::
268268

269269
from pymongo import MongoClient
270270
client = MongoClient() # error: Need type annotation for "client"
@@ -313,10 +313,10 @@ Another example is trying to set a value on a :class:`~bson.raw_bson.RawBSONDocu
313313
coll = client.test.test
314314
doc = {"my": "doc"}
315315
coll.insert_one(doc)
316-
retreived = coll.find_one({"_id": doc["_id"]})
317-
assert retreived is not None
318-
assert len(retreived.raw) > 0
319-
retreived[
316+
retrieved = coll.find_one({"_id": doc["_id"]})
317+
assert retrieved is not None
318+
assert len(retrieved.raw) > 0
319+
retrieved[
320320
"foo"
321321
] = "bar" # error: Unsupported target for indexed assignment
322322
# ("RawBSONDocument") [index]

gridfs/grid_file.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ def write(self, data: Any) -> None:
381381
def writelines(self, sequence: Iterable[Any]) -> None:
382382
"""Write a sequence of strings to the file.
383383
384-
Does not add seperators.
384+
Does not add separators.
385385
"""
386386
for line in sequence:
387387
self.write(line)

pymongo/collection.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2076,7 +2076,7 @@ def drop_indexes(
20762076
) -> None:
20772077
"""Drops all indexes on this collection.
20782078
2079-
Can be used on non-existant collections or collections with no indexes.
2079+
Can be used on non-existent collections or collections with no indexes.
20802080
Raises OperationFailure on an error.
20812081
20822082
:Parameters:
@@ -2112,7 +2112,7 @@ def drop_index(
21122112
) -> None:
21132113
"""Drops the specified index on this collection.
21142114
2115-
Can be used on non-existant collections or collections with no
2115+
Can be used on non-existent collections or collections with no
21162116
indexes. Raises OperationFailure on an error (e.g. trying to
21172117
drop an index that does not exist). `index_or_name`
21182118
can be either an index name (as returned by `create_index`),
@@ -2683,7 +2683,7 @@ def rename(
26832683
if not new_name or ".." in new_name:
26842684
raise InvalidName("collection names cannot be empty")
26852685
if new_name[0] == "." or new_name[-1] == ".":
2686-
raise InvalidName("collecion names must not start or end with '.'")
2686+
raise InvalidName("collection names must not start or end with '.'")
26872687
if "$" in new_name and not new_name.startswith("oplog.$main"):
26882688
raise InvalidName("collection names must not contain '$'")
26892689

pymongo/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ def validate_document_class(
469469
raise TypeError(
470470
"%s must be dict, bson.son.SON, "
471471
"bson.raw_bson.RawBSONDocument, or a "
472-
"sublass of collections.MutableMapping" % (option,)
472+
"subclass of collections.MutableMapping" % (option,)
473473
)
474474
return value
475475

pymongo/message.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1077,7 +1077,7 @@ def _batched_op_msg_impl(operation, command, docs, ack, opts, ctx, buf):
10771077
new_message_size = buf.tell() + doc_length
10781078
# Does first document exceed max_message_size?
10791079
doc_too_large = idx == 0 and (new_message_size > max_message_size)
1080-
# When OP_MSG is used unacknowleged we have to check
1080+
# When OP_MSG is used unacknowledged we have to check
10811081
# document size client side or applications won't be notified.
10821082
# Otherwise we let the server deal with documents that are too large
10831083
# since ordered=False causes those documents to be skipped instead of

pymongo/ocsp_support.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ def _ocsp_callback(conn, ocsp_bytes, user_data):
312312
return 0
313313
if not user_data.check_ocsp_endpoint:
314314
_LOGGER.debug("OCSP endpoint checking is disabled, soft fail.")
315-
# No stapled OCSP response, checking responder URI diabled, soft fail.
315+
# No stapled OCSP response, checking responder URI disabled, soft fail.
316316
return 1
317317
# https://tools.ietf.org/html/rfc6960#section-3.1
318318
ext = _get_extension(cert, _AuthorityInformationAccess)

pymongo/results.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def acknowledged(self) -> bool:
4545
4646
.. note::
4747
If the :attr:`acknowledged` attribute is ``False`` all other
48-
attibutes of this class will raise
48+
attributes of this class will raise
4949
:class:`~pymongo.errors.InvalidOperation` when accessed. Values for
5050
other attributes cannot be determined if the write operation was
5151
unacknowledged.

pymongo/uri_parser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
def _unquoted_percent(s):
4343
"""Check for unescaped percent signs.
4444
45-
:Paramaters:
45+
:Parameters:
4646
- `s`: A string. `s` can have things like '%25', '%2525',
4747
and '%E2%85%A8' but cannot have unquoted percent like '%foo'.
4848
"""
@@ -64,7 +64,7 @@ def parse_userinfo(userinfo: str) -> Tuple[str, str]:
6464
Returns a 2-tuple containing the unescaped username followed
6565
by the unescaped password.
6666
67-
:Paramaters:
67+
:Parameters:
6868
- `userinfo`: A string of the form <username>:<password>
6969
"""
7070
if "@" in userinfo or userinfo.count(":") > 1 or _unquoted_percent(userinfo):

test/client-side-encryption/spec/legacy/fle2v2-MissingKey.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"key_vault_data": [],
5656
"tests": [
5757
{
58-
"description": "FLE2 encrypt fails with mising key",
58+
"description": "FLE2 encrypt fails with missing key",
5959
"clientOptions": {
6060
"autoEncryptOpts": {
6161
"kmsProviders": {
@@ -86,7 +86,7 @@
8686
]
8787
},
8888
{
89-
"description": "FLE2 decrypt fails with mising key",
89+
"description": "FLE2 decrypt fails with missing key",
9090
"clientOptions": {
9191
"autoEncryptOpts": {
9292
"kmsProviders": {

test/csot/deprecated-options.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"description": "operations ignore deprected timeout options if timeoutMS is set",
2+
"description": "operations ignore deprecated timeout options if timeoutMS is set",
33
"schemaVersion": "1.9",
44
"runOnRequirements": [
55
{

test/mod_wsgi_test/mod_wsgi_test.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ WSGISocketPrefix /tmp/
2727

2828
WSGIProcessGroup mod_wsgi_test
2929

30-
# For the convienience of unittests, rather than hard-code the location of
30+
# For the convenience of unittests, rather than hard-code the location of
3131
# mod_wsgi_test.wsgi, include it in the URL, so
3232
# http://localhost/location-of-pymongo-checkout will work:
3333

test/mypy_fails/raw_bson_document.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
coll = client.test.test
66
doc = {"my": "doc"}
77
coll.insert_one(doc)
8-
retreived = coll.find_one({"_id": doc["_id"]})
9-
assert retreived is not None
10-
assert len(retreived.raw) > 0
11-
retreived[
8+
retrieved = coll.find_one({"_id": doc["_id"]})
9+
assert retrieved is not None
10+
assert len(retrieved.raw) > 0
11+
retrieved[
1212
"foo"
1313
] = "bar" # error: Unsupported target for indexed assignment ("RawBSONDocument") [index]

test/mypy_fails/typedict_client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ class Movie(TypedDict):
1010

1111
client: MongoClient[Movie] = MongoClient()
1212
coll = client.test.test
13-
retreived = coll.find_one({"_id": "foo"})
14-
assert retreived is not None
15-
assert retreived["year"] == 1
13+
retrieved = coll.find_one({"_id": "foo"})
14+
assert retrieved is not None
15+
assert retrieved["year"] == 1
1616
assert (
17-
retreived["name"] == 2
17+
retrieved["name"] == 2
1818
) # error: Non-overlapping equality check (left operand type: "str", right operand type: "Literal[2]") [comparison-overlap]

test/test_read_write_concern_spec.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ def run_test(self):
280280
self.assertEqual(write_concern.acknowledged, test_case["isAcknowledged"])
281281
self.assertEqual(write_concern.is_server_default, test_case["isServerDefault"])
282282
if "readConcern" in test_case:
283-
# Any string for 'level' is equaly valid
283+
# Any string for 'level' is equally valid
284284
read_concern = ReadConcern(**test_case["readConcern"])
285285
self.assertEqual(read_concern.document, test_case["readConcernDocument"])
286286
self.assertEqual(not bool(read_concern.level), test_case["isServerDefault"])

test/test_typing.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,11 @@ def test_insert_find(self) -> None:
111111
coll2 = self.client.test.test2
112112
result = self.coll.insert_one(doc)
113113
self.assertEqual(result.inserted_id, doc["_id"])
114-
retreived = self.coll.find_one({"_id": doc["_id"]})
115-
if retreived:
114+
retrieved = self.coll.find_one({"_id": doc["_id"]})
115+
if retrieved:
116116
# Documents returned from find are mutable.
117-
retreived["new_field"] = 1
118-
result2 = coll2.insert_one(retreived)
117+
retrieved["new_field"] = 1
118+
result2 = coll2.insert_one(retrieved)
119119
self.assertEqual(result2.inserted_id, result.inserted_id)
120120

121121
def test_cursor_iterable(self) -> None:
@@ -182,9 +182,9 @@ def test_default_document_type(self) -> None:
182182
coll = client.test.test
183183
doc = {"my": "doc"}
184184
coll.insert_one(doc)
185-
retreived = coll.find_one({"_id": doc["_id"]})
186-
assert retreived is not None
187-
retreived["a"] = 1
185+
retrieved = coll.find_one({"_id": doc["_id"]})
186+
assert retrieved is not None
187+
retrieved["a"] = 1
188188

189189
def test_aggregate_pipeline(self) -> None:
190190
coll3 = self.client.test.test3
@@ -329,26 +329,26 @@ class TestDocumentType(unittest.TestCase):
329329
def test_default(self) -> None:
330330
client: MongoClient = MongoClient()
331331
coll = client.test.test
332-
retreived = coll.find_one({"_id": "foo"})
333-
assert retreived is not None
334-
retreived["a"] = 1
332+
retrieved = coll.find_one({"_id": "foo"})
333+
assert retrieved is not None
334+
retrieved["a"] = 1
335335

336336
@only_type_check
337337
def test_explicit_document_type(self) -> None:
338338
client: MongoClient[Dict[str, Any]] = MongoClient()
339339
coll = client.test.test
340-
retreived = coll.find_one({"_id": "foo"})
341-
assert retreived is not None
342-
retreived["a"] = 1
340+
retrieved = coll.find_one({"_id": "foo"})
341+
assert retrieved is not None
342+
retrieved["a"] = 1
343343

344344
@only_type_check
345345
def test_typeddict_document_type(self) -> None:
346346
client: MongoClient[Movie] = MongoClient()
347347
coll = client.test.test
348-
retreived = coll.find_one({"_id": "foo"})
349-
assert retreived is not None
350-
assert retreived["year"] == 1
351-
assert retreived["name"] == "a"
348+
retrieved = coll.find_one({"_id": "foo"})
349+
assert retrieved is not None
350+
assert retrieved["year"] == 1
351+
assert retrieved["name"] == "a"
352352

353353
@only_type_check
354354
def test_typeddict_document_type_insertion(self) -> None:
@@ -450,17 +450,17 @@ def test_typeddict_find_notrequired(self):
450450
def test_raw_bson_document_type(self) -> None:
451451
client = MongoClient(document_class=RawBSONDocument)
452452
coll = client.test.test
453-
retreived = coll.find_one({"_id": "foo"})
454-
assert retreived is not None
455-
assert len(retreived.raw) > 0
453+
retrieved = coll.find_one({"_id": "foo"})
454+
assert retrieved is not None
455+
assert len(retrieved.raw) > 0
456456

457457
@only_type_check
458458
def test_son_document_type(self) -> None:
459459
client = MongoClient(document_class=SON[str, Any])
460460
coll = client.test.test
461-
retreived = coll.find_one({"_id": "foo"})
462-
assert retreived is not None
463-
retreived["a"] = 1
461+
retrieved = coll.find_one({"_id": "foo"})
462+
assert retrieved is not None
463+
retrieved["a"] = 1
464464

465465
def test_son_document_type_runtime(self) -> None:
466466
client = MongoClient(document_class=SON[str, Any], connect=False)

0 commit comments

Comments
 (0)