diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d8455981f..f19f15682 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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"] diff --git a/bson/__init__.py b/bson/__init__.py index 700a5d4cf..d95c511fc 100644 --- a/bson/__init__.py +++ b/bson/__init__.py @@ -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 diff --git a/bson/_cbsonmodule.c b/bson/_cbsonmodule.c index 8678e8050..e45a11be3 100644 --- a/bson/_cbsonmodule.c +++ b/bson/_cbsonmodule.c @@ -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; diff --git a/bson/objectid.py b/bson/objectid.py index 4bc024353..1fab986b8 100644 --- a/bson/objectid.py +++ b/bson/objectid.py @@ -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"] diff --git a/bson/time64.c b/bson/time64.c index 8d2886592..a21fbb90b 100644 --- a/bson/time64.c +++ b/bson/time64.c @@ -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 ) diff --git a/doc/changelog.rst b/doc/changelog.rst index 19830b09a..db2259f95 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -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 `_: When storing integers, type is selected according to value instead of type - `PYTHON-173 `_: - as_class option is not propogated by Cursor.clone + as_class option is not propagated by Cursor.clone - `PYTHON-113 `_: Redunducy in MasterSlaveConnection diff --git a/doc/contributors.rst b/doc/contributors.rst index 7ab87f779..7efda5b20 100644 --- a/doc/contributors.rst +++ b/doc/contributors.rst @@ -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) diff --git a/doc/examples/bulk.rst b/doc/examples/bulk.rst index c2c5acc68..3ed8e0964 100644 --- a/doc/examples/bulk.rst +++ b/doc/examples/bulk.rst @@ -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. diff --git a/doc/examples/type_hints.rst b/doc/examples/type_hints.rst index f202ab32e..8aaaff81e 100644 --- a/doc/examples/type_hints.rst +++ b/doc/examples/type_hints.rst @@ -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] diff --git a/gridfs/grid_file.py b/gridfs/grid_file.py index 50efc0cd2..5ec635268 100644 --- a/gridfs/grid_file.py +++ b/gridfs/grid_file.py @@ -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) diff --git a/pymongo/collection.py b/pymongo/collection.py index ac78b6878..91b4013ee 100644 --- a/pymongo/collection.py +++ b/pymongo/collection.py @@ -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 '$'") diff --git a/pymongo/common.py b/pymongo/common.py index ba861c154..4b8aeb020 100644 --- a/pymongo/common.py +++ b/pymongo/common.py @@ -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 diff --git a/pymongo/message.py b/pymongo/message.py index 9fa64a875..f7a173ca8 100644 --- a/pymongo/message.py +++ b/pymongo/message.py @@ -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 diff --git a/pymongo/ocsp_support.py b/pymongo/ocsp_support.py index 3a201f1f5..e7f4a15d8 100644 --- a/pymongo/ocsp_support.py +++ b/pymongo/ocsp_support.py @@ -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) diff --git a/pymongo/results.py b/pymongo/results.py index 580390039..b07297949 100644 --- a/pymongo/results.py +++ b/pymongo/results.py @@ -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. diff --git a/pymongo/uri_parser.py b/pymongo/uri_parser.py index 398dfbff0..e3aeee399 100644 --- a/pymongo/uri_parser.py +++ b/pymongo/uri_parser.py @@ -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 : """ if "@" in userinfo or userinfo.count(":") > 1 or _unquoted_percent(userinfo): diff --git a/test/client-side-encryption/spec/legacy/fle2v2-MissingKey.json b/test/client-side-encryption/spec/legacy/fle2v2-MissingKey.json index 0b7e86bca..a07245411 100644 --- a/test/client-side-encryption/spec/legacy/fle2v2-MissingKey.json +++ b/test/client-side-encryption/spec/legacy/fle2v2-MissingKey.json @@ -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": { diff --git a/test/csot/deprecated-options.json b/test/csot/deprecated-options.json index 0e2bdefd7..9c9b9a228 100644 --- a/test/csot/deprecated-options.json +++ b/test/csot/deprecated-options.json @@ -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": [ { diff --git a/test/mod_wsgi_test/mod_wsgi_test.conf b/test/mod_wsgi_test/mod_wsgi_test.conf index 9505933e9..6a77c675d 100644 --- a/test/mod_wsgi_test/mod_wsgi_test.conf +++ b/test/mod_wsgi_test/mod_wsgi_test.conf @@ -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: diff --git a/test/mypy_fails/raw_bson_document.py b/test/mypy_fails/raw_bson_document.py index 427140dfa..0e1722487 100644 --- a/test/mypy_fails/raw_bson_document.py +++ b/test/mypy_fails/raw_bson_document.py @@ -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] diff --git a/test/mypy_fails/typedict_client.py b/test/mypy_fails/typedict_client.py index 24dd84ee2..6619df10f 100644 --- a/test/mypy_fails/typedict_client.py +++ b/test/mypy_fails/typedict_client.py @@ -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] diff --git a/test/test_read_write_concern_spec.py b/test/test_read_write_concern_spec.py index 5cc4845e3..26bc111f0 100644 --- a/test/test_read_write_concern_spec.py +++ b/test/test_read_write_concern_spec.py @@ -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"]) diff --git a/test/test_typing.py b/test/test_typing.py index 8fc0f5a23..0aebc707c 100644 --- a/test/test_typing.py +++ b/test/test_typing.py @@ -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)