From c6a6ea60663ce37cbd5128f1a83bc46e54fb2071 Mon Sep 17 00:00:00 2001 From: Soroush Mahdavi <55580458+sushiboytr@users.noreply.github.com> Date: Fri, 14 Jul 2023 12:30:14 -0700 Subject: [PATCH] PYTHON-3511 Remove Python 2 references from the docs (#1161) Co-authored-by: Nicky Lee <40870742+iceypotato@users.noreply.github.com> Co-authored-by: DanielZavala11 <89770626+DanielZavala11@users.noreply.github.com> Co-authored-by: Shane Harvey --- bson/__init__.py | 12 +++++------- bson/code.py | 4 ++-- bson/dbref.py | 8 ++++---- bson/objectid.py | 5 ++--- gridfs/grid_file.py | 4 ++-- pymongo/collection.py | 16 +++++++--------- pymongo/cursor.py | 18 ++++++++---------- pymongo/database.py | 11 +++++------ pymongo/mongo_client.py | 3 +-- pymongo/operations.py | 5 ++--- 10 files changed, 38 insertions(+), 48 deletions(-) diff --git a/bson/__init__.py b/bson/__init__.py index b6ed4ad0e..8f8d58562 100644 --- a/bson/__init__.py +++ b/bson/__init__.py @@ -814,7 +814,7 @@ def _encode_timestamp(name: bytes, value: Any, dummy0: Any, dummy1: Any) -> byte def _encode_long(name: bytes, value: Any, dummy0: Any, dummy1: Any) -> bytes: - """Encode a python long (python 2.x)""" + """Encode a bson.int64.Int64.""" try: return b"\x12" + name + _PACK_LONG(value) except struct.error: @@ -1004,8 +1004,7 @@ def encode( A document can be any mapping type (like :class:`dict`). Raises :class:`TypeError` if `document` is not a mapping type, - or contains keys that are not instances of - :class:`basestring` (:class:`str` in python 3). Raises + or contains keys that are not instances of :class:`str`. Raises :class:`~bson.errors.InvalidDocument` if `document` cannot be converted to :class:`BSON`. @@ -1316,7 +1315,7 @@ def is_valid(bson: bytes) -> bool: """Check that the given string represents valid :class:`BSON` data. Raises :class:`TypeError` if `bson` is not an instance of - :class:`str` (:class:`bytes` in python 3). Returns ``True`` + :class:`bytes`. Returns ``True`` if `bson` is valid :class:`BSON`, ``False`` otherwise. :Parameters: @@ -1353,9 +1352,8 @@ class BSON(bytes): Raises :class:`TypeError` if `document` is not a mapping type, or contains keys that are not instances of - :class:`basestring` (:class:`str` in python 3). Raises - :class:`~bson.errors.InvalidDocument` if `document` cannot be - converted to :class:`BSON`. + :class:`str'. Raises :class:`~bson.errors.InvalidDocument` + if `document` cannot be converted to :class:`BSON`. :Parameters: - `document`: mapping type representing a document diff --git a/bson/code.py b/bson/code.py index 27ec588fa..37b2aa85d 100644 --- a/bson/code.py +++ b/bson/code.py @@ -22,8 +22,8 @@ class Code(str): """BSON's JavaScript code type. Raises :class:`TypeError` if `code` is not an instance of - :class:`basestring` (:class:`str` in python 3) or `scope` - is not ``None`` or an instance of :class:`dict`. + :class:`str` or `scope` is not ``None`` or an instance + of :class:`dict`. Scope variables can be set by passing a dictionary as the `scope` argument or by using keyword arguments. If a variable is set as a diff --git a/bson/dbref.py b/bson/dbref.py index 491278e6f..1141e7ba1 100644 --- a/bson/dbref.py +++ b/bson/dbref.py @@ -41,10 +41,10 @@ class DBRef: """Initialize a new :class:`DBRef`. Raises :class:`TypeError` if `collection` or `database` is not - an instance of :class:`basestring` (:class:`str` in python 3). - `database` is optional and allows references to documents to work - across databases. Any additional keyword arguments will create - additional fields in the resultant embedded document. + an instance of :class:`str`. `database` is optional and allows + references to documents to work across databases. Any additional + keyword arguments will create additional fields in the resultant + embedded document. :Parameters: - `collection`: name of the collection the document is stored in diff --git a/bson/objectid.py b/bson/objectid.py index b045e93d0..966fd9f94 100644 --- a/bson/objectid.py +++ b/bson/objectid.py @@ -181,9 +181,8 @@ class ObjectId: def __validate(self, oid: Any) -> None: """Validate and use the given id for this ObjectId. - Raises TypeError if id is not an instance of - (:class:`basestring` (:class:`str` or :class:`bytes` - in python 3), ObjectId) and InvalidId if it is not a + Raises TypeError if id is not an instance of :class:`str`, + :class:`bytes`, or ObjectId. Raises InvalidId if it is not a valid ObjectId. :Parameters: diff --git a/gridfs/grid_file.py b/gridfs/grid_file.py index 4afedba8a..7a09f35ef 100644 --- a/gridfs/grid_file.py +++ b/gridfs/grid_file.py @@ -592,8 +592,8 @@ class GridOut(io.IOBase): """Read at most `size` bytes from the file (less if there isn't enough data). - The bytes are returned as an instance of :class:`str` (:class:`bytes` - in python 3). If `size` is negative or omitted all data is read. + The bytes are returned as an instance of :class:`bytes` + If `size` is negative or omitted all data is read. :Parameters: - `size` (optional): the number of bytes to read diff --git a/pymongo/collection.py b/pymongo/collection.py index 9bee452d0..6a1bcf8c0 100644 --- a/pymongo/collection.py +++ b/pymongo/collection.py @@ -149,9 +149,8 @@ class Collection(common.BaseObject, Generic[_DocumentType]): """Get / create a Mongo collection. Raises :class:`TypeError` if `name` is not an instance of - :class:`basestring` (:class:`str` in python 3). Raises - :class:`~pymongo.errors.InvalidName` if `name` is not a valid - collection name. Any additional keyword arguments will be used + :class:`str`. Raises :class:`~pymongo.errors.InvalidName` if `name` is + not a valid collection name. Any additional keyword arguments will be used as options passed to the create command. See :meth:`~pymongo.database.Database.create_collection` for valid options. @@ -2037,9 +2036,8 @@ class Collection(common.BaseObject, Generic[_DocumentType]): Takes either a single key or a list containing (key, direction) pairs or keys. If no direction is given, :data:`~pymongo.ASCENDING` will be assumed. - The key(s) must be an instance of :class:`basestring` - (:class:`str` in python 3), and the direction(s) must be one of - (:data:`~pymongo.ASCENDING`, :data:`~pymongo.DESCENDING`, + The key(s) must be an instance of :class:`str`and the direction(s) must + be one of (:data:`~pymongo.ASCENDING`, :data:`~pymongo.DESCENDING`, :data:`~pymongo.GEO2D`, :data:`~pymongo.GEOSPHERE`, :data:`~pymongo.HASHED`, :data:`~pymongo.TEXT`). @@ -2940,8 +2938,8 @@ class Collection(common.BaseObject, Generic[_DocumentType]): If operating in auth mode, client must be authorized as an admin to perform this operation. Raises :class:`TypeError` if - `new_name` is not an instance of :class:`basestring` - (:class:`str` in python 3). Raises :class:`~pymongo.errors.InvalidName` + `new_name` is not an instance of :class:`str`. + Raises :class:`~pymongo.errors.InvalidName` if `new_name` is not a valid collection name. :Parameters: @@ -3005,7 +3003,7 @@ class Collection(common.BaseObject, Generic[_DocumentType]): in this collection. Raises :class:`TypeError` if `key` is not an instance of - :class:`basestring` (:class:`str` in python 3). + :class:`str`. All optional distinct parameters should be passed as keyword arguments to this method. Valid options include: diff --git a/pymongo/cursor.py b/pymongo/cursor.py index b67a8ad42..b718d905e 100644 --- a/pymongo/cursor.py +++ b/pymongo/cursor.py @@ -887,7 +887,7 @@ class Cursor(Generic[_DocumentType]): in the result set of this query. Raises :class:`TypeError` if `key` is not an instance of - :class:`basestring` (:class:`str` in python 3). + :class:`str`. The :meth:`distinct` method obeys the :attr:`~pymongo.collection.Collection.read_preference` of the @@ -984,21 +984,19 @@ class Cursor(Generic[_DocumentType]): def where(self, code: Union[str, Code]) -> "Cursor[_DocumentType]": """Adds a `$where`_ clause to this query. - The `code` argument must be an instance of :class:`basestring` - (:class:`str` in python 3) or :class:`~bson.code.Code` - containing a JavaScript expression. This expression will be - evaluated for each document scanned. Only those documents - for which the expression evaluates to *true* will be returned - as results. The keyword *this* refers to the object currently - being scanned. For example:: + The `code` argument must be an instance of :class:`str` or + :class:`~bson.code.Code` containing a JavaScript expression. + This expression will be evaluated for each document scanned. + Only those documents for which the expression evaluates to + *true* will be returned as results. The keyword *this* refers + to the object currently being scanned. For example:: # Find all documents where field "a" is less than "b" plus "c". for doc in db.test.find().where('this.a < (this.b + this.c)'): print(doc) Raises :class:`TypeError` if `code` is not an instance of - :class:`basestring` (:class:`str` in python 3). Raises - :class:`~pymongo.errors.InvalidOperation` if this + :class:`str`. Raises :class:`~pymongo.errors.InvalidOperation` if this :class:`Cursor` has already been used. Only the last call to :meth:`where` applied to a :class:`Cursor` has any effect. diff --git a/pymongo/database.py b/pymongo/database.py index dac82d0c6..a55555cc4 100644 --- a/pymongo/database.py +++ b/pymongo/database.py @@ -89,9 +89,8 @@ class Database(common.BaseObject, Generic[_DocumentType]): """Get a database by client and name. Raises :class:`TypeError` if `name` is not an instance of - :class:`basestring` (:class:`str` in python 3). Raises - :class:`~pymongo.errors.InvalidName` if `name` is not a valid - database name. + :class:`str`. Raises :class:`~pymongo.errors.InvalidName` if + `name` is not a valid database name. :Parameters: - `client`: A :class:`~pymongo.mongo_client.MongoClient` instance. @@ -802,9 +801,9 @@ class Database(common.BaseObject, Generic[_DocumentType]): """Issue a MongoDB command. Send command `command` to the database and return the - response. If `command` is an instance of :class:`basestring` - (:class:`str` in python 3) then the command {`command`: `value`} - will be sent. Otherwise, `command` must be an instance of + response. If `command` is an instance of :class:`str` + then the command {`command`: `value`} will be sent. + Otherwise, `command` must be an instance of :class:`dict` and will be sent as is. Any additional keyword arguments will be added to the final diff --git a/pymongo/mongo_client.py b/pymongo/mongo_client.py index 871c4545e..96b5a5158 100644 --- a/pymongo/mongo_client.py +++ b/pymongo/mongo_client.py @@ -1894,8 +1894,7 @@ class MongoClient(common.BaseObject, Generic[_DocumentType]): """Drop a database. Raises :class:`TypeError` if `name_or_database` is not an instance of - :class:`basestring` (:class:`str` in python 3) or - :class:`~pymongo.database.Database`. + :class:`str` or :class:`~pymongo.database.Database`. :Parameters: - `name_or_database`: the name of a database to drop, or a diff --git a/pymongo/operations.py b/pymongo/operations.py index 3a7aedb86..67eead35e 100644 --- a/pymongo/operations.py +++ b/pymongo/operations.py @@ -452,9 +452,8 @@ class IndexModel: Takes either a single key or a list containing (key, direction) pairs or keys. If no direction is given, :data:`~pymongo.ASCENDING` will be assumed. - The key(s) must be an instance of :class:`basestring` - (:class:`str` in python 3), and the direction(s) must be one of - (:data:`~pymongo.ASCENDING`, :data:`~pymongo.DESCENDING`, + The key(s) must be an instance of :class:`str`, and the direction(s) must + be one of (:data:`~pymongo.ASCENDING`, :data:`~pymongo.DESCENDING`, :data:`~pymongo.GEO2D`, :data:`~pymongo.GEOSPHERE`, :data:`~pymongo.HASHED`, :data:`~pymongo.TEXT`).