PYTHON-3703 Fix typos and add codespell pre-commit hook (#1203)

Update pre-commit config adding "codespell" hook
This commit is contained in:
Jean-Christophe Fillion-Robin 2023-05-03 17:47:24 -04:00 committed by GitHub
parent 14e8b011c2
commit d340710e3d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 73 additions and 59 deletions

View File

@ -83,3 +83,16 @@ repos:
files: \.py$
exclude: "^(test|tools)/"
stages: [manual]
- repo: https://github.com/codespell-project/codespell
rev: "v2.2.4"
hooks:
- id: codespell
# Examples of errors or updates to justify the exceptions:
# - test/test_on_demand_csfle.py:44: FLE ==> FILE
# - test/test_bson.py:1043: fo ==> of, for, to, do, go
# - test/bson_corpus/decimal128-4.json:98: Infinit ==> Infinite
# - test/test_bson.py:267: isnt ==> isn't
# - test/versioned-api/crud-api-version-1-strict.json:514: nin ==> inn, min, bin, nine
# - test/test_client.py:188: te ==> the, be, we, to
args: ["-L", "fle,fo,infinit,isnt,nin,te"]

View File

@ -1282,7 +1282,7 @@ def decode_file_iter(
# Read size of next object.
size_data = file_obj.read(4)
if not size_data:
break # Finished with file normaly.
break # Finished with file normally.
elif len(size_data) != 4:
raise InvalidBSON("cut off in middle of objsize")
obj_size = _UNPACK_INT_FROM(size_data, 0)[0] - 4

View File

@ -968,7 +968,7 @@ static int _write_element_to_buffer(PyObject* self, buffer_t buffer,
}
}
/* No _type_marker attibute or not one of our types. */
/* No _type_marker attribute or not one of our types. */
if (PyBool_Check(value)) {
const char c = (value == Py_True) ? 0x01 : 0x00;

View File

@ -231,7 +231,7 @@ class ObjectId(object):
def __setstate__(self, value: Any) -> None:
"""explicit state set from pickling"""
# Provide backwards compatability with OIDs
# Provide backwards compatibility with OIDs
# pickled with pymongo-1.9 or older.
if isinstance(value, dict):
oid = value["_ObjectId__id"]

View File

@ -73,7 +73,7 @@ static const Year years_in_gregorian_cycle = 400;
#define days_in_gregorian_cycle ((365 * 400) + 100 - 4 + 1)
static const Time64_T seconds_in_gregorian_cycle = days_in_gregorian_cycle * 60LL * 60LL * 24LL;
/* Year range we can trust the time funcitons with */
/* Year range we can trust the time functions with */
#define MAX_SAFE_YEAR 2037
#define MIN_SAFE_YEAR 1971
@ -739,7 +739,7 @@ struct TM *cbson_localtime64_r (const Time64_T *time, struct TM *local_tm)
/* GMT is Jan 1st, xx01 year, but localtime is still Dec 31st
in a non-leap xx00. There is one point in the cycle
we can't account for which the safe xx00 year is a leap
year. So we need to correct for Dec 31st comming out as
year. So we need to correct for Dec 31st coming out as
the 366th day of the year.
*/
if( !IS_LEAP(local_tm->tm_year) && local_tm->tm_yday == 365 )

View File

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

View File

@ -93,3 +93,4 @@ The following is a list of people who have contributed to
- Ishmum Jawad Khan (ishmum123)
- Arie Bovenberg (ariebovenberg)
- Ben Warner (bcwarner)
- Jean-Christophe Fillion-Robin (jcfr)

View File

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

View File

@ -264,7 +264,7 @@ Troubleshooting
Client Type Annotation
~~~~~~~~~~~~~~~~~~~~~~
If you forget to add a type annotation for a :class:`~pymongo.mongo_client.MongoClient` object you may get the followig ``mypy`` error::
If you forget to add a type annotation for a :class:`~pymongo.mongo_client.MongoClient` object you may get the following ``mypy`` error::
from pymongo import MongoClient
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
coll = client.test.test
doc = {"my": "doc"}
coll.insert_one(doc)
retreived = coll.find_one({"_id": doc["_id"]})
assert retreived is not None
assert len(retreived.raw) > 0
retreived[
retrieved = coll.find_one({"_id": doc["_id"]})
assert retrieved is not None
assert len(retrieved.raw) > 0
retrieved[
"foo"
] = "bar" # error: Unsupported target for indexed assignment
# ("RawBSONDocument") [index]

View File

@ -381,7 +381,7 @@ class GridIn(object):
def writelines(self, sequence: Iterable[Any]) -> None:
"""Write a sequence of strings to the file.
Does not add seperators.
Does not add separators.
"""
for line in sequence:
self.write(line)

View File

@ -2076,7 +2076,7 @@ class Collection(common.BaseObject, Generic[_DocumentType]):
) -> None:
"""Drops all indexes on this collection.
Can be used on non-existant collections or collections with no indexes.
Can be used on non-existent collections or collections with no indexes.
Raises OperationFailure on an error.
:Parameters:
@ -2112,7 +2112,7 @@ class Collection(common.BaseObject, Generic[_DocumentType]):
) -> None:
"""Drops the specified index on this collection.
Can be used on non-existant collections or collections with no
Can be used on non-existent collections or collections with no
indexes. Raises OperationFailure on an error (e.g. trying to
drop an index that does not exist). `index_or_name`
can be either an index name (as returned by `create_index`),
@ -2683,7 +2683,7 @@ class Collection(common.BaseObject, Generic[_DocumentType]):
if not new_name or ".." in new_name:
raise InvalidName("collection names cannot be empty")
if new_name[0] == "." or new_name[-1] == ".":
raise InvalidName("collecion names must not start or end with '.'")
raise InvalidName("collection names must not start or end with '.'")
if "$" in new_name and not new_name.startswith("oplog.$main"):
raise InvalidName("collection names must not contain '$'")

View File

@ -469,7 +469,7 @@ def validate_document_class(
raise TypeError(
"%s must be dict, bson.son.SON, "
"bson.raw_bson.RawBSONDocument, or a "
"sublass of collections.MutableMapping" % (option,)
"subclass of collections.MutableMapping" % (option,)
)
return value

View File

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

View File

@ -312,7 +312,7 @@ def _ocsp_callback(conn, ocsp_bytes, user_data):
return 0
if not user_data.check_ocsp_endpoint:
_LOGGER.debug("OCSP endpoint checking is disabled, soft fail.")
# No stapled OCSP response, checking responder URI diabled, soft fail.
# No stapled OCSP response, checking responder URI disabled, soft fail.
return 1
# https://tools.ietf.org/html/rfc6960#section-3.1
ext = _get_extension(cert, _AuthorityInformationAccess)

View File

@ -45,7 +45,7 @@ class _WriteResult(object):
.. note::
If the :attr:`acknowledged` attribute is ``False`` all other
attibutes of this class will raise
attributes of this class will raise
:class:`~pymongo.errors.InvalidOperation` when accessed. Values for
other attributes cannot be determined if the write operation was
unacknowledged.

View File

@ -42,7 +42,7 @@ DEFAULT_PORT = 27017
def _unquoted_percent(s):
"""Check for unescaped percent signs.
:Paramaters:
:Parameters:
- `s`: A string. `s` can have things like '%25', '%2525',
and '%E2%85%A8' but cannot have unquoted percent like '%foo'.
"""
@ -64,7 +64,7 @@ def parse_userinfo(userinfo: str) -> Tuple[str, str]:
Returns a 2-tuple containing the unescaped username followed
by the unescaped password.
:Paramaters:
:Parameters:
- `userinfo`: A string of the form <username>:<password>
"""
if "@" in userinfo or userinfo.count(":") > 1 or _unquoted_percent(userinfo):

View File

@ -55,7 +55,7 @@
"key_vault_data": [],
"tests": [
{
"description": "FLE2 encrypt fails with mising key",
"description": "FLE2 encrypt fails with missing key",
"clientOptions": {
"autoEncryptOpts": {
"kmsProviders": {
@ -86,7 +86,7 @@
]
},
{
"description": "FLE2 decrypt fails with mising key",
"description": "FLE2 decrypt fails with missing key",
"clientOptions": {
"autoEncryptOpts": {
"kmsProviders": {

View File

@ -1,5 +1,5 @@
{
"description": "operations ignore deprected timeout options if timeoutMS is set",
"description": "operations ignore deprecated timeout options if timeoutMS is set",
"schemaVersion": "1.9",
"runOnRequirements": [
{

View File

@ -27,7 +27,7 @@ WSGISocketPrefix /tmp/
WSGIProcessGroup mod_wsgi_test
# For the convienience of unittests, rather than hard-code the location of
# For the convenience of unittests, rather than hard-code the location of
# mod_wsgi_test.wsgi, include it in the URL, so
# http://localhost/location-of-pymongo-checkout will work:

View File

@ -5,9 +5,9 @@ client = MongoClient(document_class=RawBSONDocument)
coll = client.test.test
doc = {"my": "doc"}
coll.insert_one(doc)
retreived = coll.find_one({"_id": doc["_id"]})
assert retreived is not None
assert len(retreived.raw) > 0
retreived[
retrieved = coll.find_one({"_id": doc["_id"]})
assert retrieved is not None
assert len(retrieved.raw) > 0
retrieved[
"foo"
] = "bar" # error: Unsupported target for indexed assignment ("RawBSONDocument") [index]

View File

@ -10,9 +10,9 @@ class Movie(TypedDict):
client: MongoClient[Movie] = MongoClient()
coll = client.test.test
retreived = coll.find_one({"_id": "foo"})
assert retreived is not None
assert retreived["year"] == 1
retrieved = coll.find_one({"_id": "foo"})
assert retrieved is not None
assert retrieved["year"] == 1
assert (
retreived["name"] == 2
retrieved["name"] == 2
) # error: Non-overlapping equality check (left operand type: "str", right operand type: "Literal[2]") [comparison-overlap]

View File

@ -280,7 +280,7 @@ def create_document_test(test_case):
self.assertEqual(write_concern.acknowledged, test_case["isAcknowledged"])
self.assertEqual(write_concern.is_server_default, test_case["isServerDefault"])
if "readConcern" in test_case:
# Any string for 'level' is equaly valid
# Any string for 'level' is equally valid
read_concern = ReadConcern(**test_case["readConcern"])
self.assertEqual(read_concern.document, test_case["readConcernDocument"])
self.assertEqual(not bool(read_concern.level), test_case["isServerDefault"])

View File

@ -111,11 +111,11 @@ class TestPymongo(IntegrationTest):
coll2 = self.client.test.test2
result = self.coll.insert_one(doc)
self.assertEqual(result.inserted_id, doc["_id"])
retreived = self.coll.find_one({"_id": doc["_id"]})
if retreived:
retrieved = self.coll.find_one({"_id": doc["_id"]})
if retrieved:
# Documents returned from find are mutable.
retreived["new_field"] = 1
result2 = coll2.insert_one(retreived)
retrieved["new_field"] = 1
result2 = coll2.insert_one(retrieved)
self.assertEqual(result2.inserted_id, result.inserted_id)
def test_cursor_iterable(self) -> None:
@ -182,9 +182,9 @@ class TestPymongo(IntegrationTest):
coll = client.test.test
doc = {"my": "doc"}
coll.insert_one(doc)
retreived = coll.find_one({"_id": doc["_id"]})
assert retreived is not None
retreived["a"] = 1
retrieved = coll.find_one({"_id": doc["_id"]})
assert retrieved is not None
retrieved["a"] = 1
def test_aggregate_pipeline(self) -> None:
coll3 = self.client.test.test3
@ -329,26 +329,26 @@ class TestDocumentType(unittest.TestCase):
def test_default(self) -> None:
client: MongoClient = MongoClient()
coll = client.test.test
retreived = coll.find_one({"_id": "foo"})
assert retreived is not None
retreived["a"] = 1
retrieved = coll.find_one({"_id": "foo"})
assert retrieved is not None
retrieved["a"] = 1
@only_type_check
def test_explicit_document_type(self) -> None:
client: MongoClient[Dict[str, Any]] = MongoClient()
coll = client.test.test
retreived = coll.find_one({"_id": "foo"})
assert retreived is not None
retreived["a"] = 1
retrieved = coll.find_one({"_id": "foo"})
assert retrieved is not None
retrieved["a"] = 1
@only_type_check
def test_typeddict_document_type(self) -> None:
client: MongoClient[Movie] = MongoClient()
coll = client.test.test
retreived = coll.find_one({"_id": "foo"})
assert retreived is not None
assert retreived["year"] == 1
assert retreived["name"] == "a"
retrieved = coll.find_one({"_id": "foo"})
assert retrieved is not None
assert retrieved["year"] == 1
assert retrieved["name"] == "a"
@only_type_check
def test_typeddict_document_type_insertion(self) -> None:
@ -450,17 +450,17 @@ class TestDocumentType(unittest.TestCase):
def test_raw_bson_document_type(self) -> None:
client = MongoClient(document_class=RawBSONDocument)
coll = client.test.test
retreived = coll.find_one({"_id": "foo"})
assert retreived is not None
assert len(retreived.raw) > 0
retrieved = coll.find_one({"_id": "foo"})
assert retrieved is not None
assert len(retrieved.raw) > 0
@only_type_check
def test_son_document_type(self) -> None:
client = MongoClient(document_class=SON[str, Any])
coll = client.test.test
retreived = coll.find_one({"_id": "foo"})
assert retreived is not None
retreived["a"] = 1
retrieved = coll.find_one({"_id": "foo"})
assert retrieved is not None
retrieved["a"] = 1
def test_son_document_type_runtime(self) -> None:
client = MongoClient(document_class=SON[str, Any], connect=False)