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 <shane.harvey@mongodb.com>
This commit is contained in:
Soroush Mahdavi 2023-07-14 12:30:14 -07:00 committed by GitHub
parent 992df04da6
commit c6a6ea6066
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 38 additions and 48 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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:

View File

@ -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

View File

@ -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:

View File

@ -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.

View File

@ -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

View File

@ -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

View File

@ -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`).