Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .evergreen/scripts/setup_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def get_distro() -> Distro:
version_id = ""
arch = platform.machine()
with open("/etc/os-release") as fid:
for line in fid.readlines():
for line in fid:
line = line.replace('"', "") # noqa: PLW2901
if line.startswith("NAME="):
_, _, name = line.strip().partition("=")
Expand Down
2 changes: 1 addition & 1 deletion .evergreen/scripts/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ def handle_env_overrides(parser: argparse.ArgumentParser, opts: argparse.Namespa
def read_env(path: Path | str) -> dict[str, str]:
config = dict()
with Path(path).open() as fid:
for line in fid.readlines():
for line in fid:
if "=" not in line:
continue
name, _, value = line.strip().partition("=")
Expand Down
1 change: 1 addition & 0 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ if user.email and "@" in user.email and len(user.email) > 5:
else:
submit_button.enabled = False


# Consider:
def valid_email(email):
return email and "@" in email and len(email) > 5
Expand Down
6 changes: 3 additions & 3 deletions bson/binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def __init__(
def __repr__(self) -> str:
return f"BinaryVector(dtype={self.dtype}, padding={self.padding}, data={self.data})"

def __eq__(self, other: Any) -> bool:
def __eq__(self, other: object) -> bool:
if not isinstance(other, BinaryVector):
return False
return (
Expand Down Expand Up @@ -648,7 +648,7 @@ def __getnewargs__(self) -> tuple[bytes, int]: # type: ignore[override]
data = data.encode("latin-1")
return data, self.__subtype

def __eq__(self, other: Any) -> bool:
def __eq__(self, other: object) -> bool:
if isinstance(other, Binary):
return (self.__subtype, bytes(self)) == (other.subtype, bytes(other))
# We don't return NotImplemented here because if we did then
Expand All @@ -659,7 +659,7 @@ def __eq__(self, other: Any) -> bool:
def __hash__(self) -> int:
return super().__hash__() ^ hash(self.__subtype)

def __ne__(self, other: Any) -> bool:
def __ne__(self, other: object) -> bool:
return not self == other

def __repr__(self) -> str:
Expand Down
4 changes: 2 additions & 2 deletions bson/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ def scope(self) -> Mapping[str, Any] | None:
def __repr__(self) -> str:
return f"Code({str.__repr__(self)}, {self.__scope!r})"

def __eq__(self, other: Any) -> bool:
def __eq__(self, other: object) -> bool:
if isinstance(other, Code):
return (self.__scope, str(self)) == (other.__scope, str(other))
return False

__hash__: Any = None

def __ne__(self, other: Any) -> bool:
def __ne__(self, other: object) -> bool:
return not self == other
2 changes: 1 addition & 1 deletion bson/codec_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def _validate_type_encoder(self, codec: _Codec) -> None:
def __repr__(self) -> str:
return f"{self.__class__.__name__}(type_codecs={self.__type_codecs!r}, fallback_encoder={self._fallback_encoder!r})"

def __eq__(self, other: Any) -> Any:
def __eq__(self, other: object) -> Any:
if not isinstance(other, type(self)):
return NotImplemented
return (
Expand Down
4 changes: 2 additions & 2 deletions bson/datetime_ms.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ def __lt__(self, other: DatetimeMS | int) -> bool:
def __le__(self, other: DatetimeMS | int) -> bool:
return self._value <= other

def __eq__(self, other: Any) -> bool:
def __eq__(self, other: object) -> bool:
if isinstance(other, DatetimeMS):
return self._value == other._value
return False

def __ne__(self, other: Any) -> bool:
def __ne__(self, other: object) -> bool:
if isinstance(other, DatetimeMS):
return self._value != other._value
return True
Expand Down
4 changes: 2 additions & 2 deletions bson/dbref.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,14 @@ def __repr__(self) -> str:
return f"DBRef({self.collection!r}, {self.id!r}{extra})"
return f"DBRef({self.collection!r}, {self.id!r}, {self.database!r}{extra})"

def __eq__(self, other: Any) -> bool:
def __eq__(self, other: object) -> bool:
if isinstance(other, DBRef):
us = (self.__database, self.__collection, self.__id, self.__kwargs)
them = (other.__database, other.__collection, other.__id, other.__kwargs)
return us == them
return NotImplemented

def __ne__(self, other: Any) -> bool:
def __ne__(self, other: object) -> bool:
return not self == other

def __hash__(self) -> int:
Expand Down
4 changes: 2 additions & 2 deletions bson/decimal128.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,12 +350,12 @@ def __setstate__(self, value: tuple[int, int]) -> None:
def __getstate__(self) -> tuple[int, int]:
return self.__high, self.__low

def __eq__(self, other: Any) -> bool:
def __eq__(self, other: object) -> bool:
if isinstance(other, Decimal128):
return self.bid == other.bid
return NotImplemented

__hash__ = None # type: ignore[assignment]

def __ne__(self, other: Any) -> bool:
def __ne__(self, other: object) -> bool:
return not self == other
12 changes: 6 additions & 6 deletions bson/json_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,12 @@
from bson.tz_util import utc

_RE_OPT_TABLE = {
"i": re.I,
"l": re.L,
"m": re.M,
"s": re.S,
"u": re.U,
"x": re.X,
"i": re.IGNORECASE,
"l": re.LOCALE,
"m": re.MULTILINE,
"s": re.DOTALL,
"u": re.UNICODE,
"x": re.VERBOSE,
}


Expand Down
4 changes: 2 additions & 2 deletions bson/max_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ def __getstate__(self) -> Any:
def __setstate__(self, state: Any) -> None:
pass

def __eq__(self, other: Any) -> bool:
def __eq__(self, other: object) -> bool:
return isinstance(other, MaxKey)

def __hash__(self) -> int:
return hash(self._type_marker)

def __ne__(self, other: Any) -> bool:
def __ne__(self, other: object) -> bool:
return not self == other

def __le__(self, other: Any) -> bool:
Expand Down
4 changes: 2 additions & 2 deletions bson/min_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ def __getstate__(self) -> Any:
def __setstate__(self, state: Any) -> None:
pass

def __eq__(self, other: Any) -> bool:
def __eq__(self, other: object) -> bool:
return isinstance(other, MinKey)

def __hash__(self) -> int:
return hash(self._type_marker)

def __ne__(self, other: Any) -> bool:
def __ne__(self, other: object) -> bool:
return not self == other

def __le__(self, dummy: Any) -> bool:
Expand Down
4 changes: 2 additions & 2 deletions bson/objectid.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,12 @@ def __str__(self) -> str:
def __repr__(self) -> str:
return f"ObjectId('{self!s}')"

def __eq__(self, other: Any) -> bool:
def __eq__(self, other: object) -> bool:
if isinstance(other, ObjectId):
return self.__id == other.binary
return NotImplemented

def __ne__(self, other: Any) -> bool:
def __ne__(self, other: object) -> bool:
if isinstance(other, ObjectId):
return self.__id != other.binary
return NotImplemented
Expand Down
2 changes: 1 addition & 1 deletion bson/raw_bson.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def __iter__(self) -> Iterator[str]:
def __len__(self) -> int:
return len(self.__inflated)

def __eq__(self, other: Any) -> bool:
def __eq__(self, other: object) -> bool:
if isinstance(other, RawBSONDocument):
return self.__raw == other.raw
return NotImplemented
Expand Down
4 changes: 2 additions & 2 deletions bson/regex.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ def __init__(self, pattern: _T, flags: str | int = 0) -> None:
else:
raise TypeError(f"flags must be a string or int, not {type(flags)}")

def __eq__(self, other: Any) -> bool:
def __eq__(self, other: object) -> bool:
if isinstance(other, Regex):
return self.pattern == other.pattern and self.flags == other.flags
else:
return NotImplemented

__hash__ = None # type: ignore

def __ne__(self, other: Any) -> bool:
def __ne__(self, other: object) -> bool:
return not self == other

def __repr__(self) -> str:
Expand Down
6 changes: 3 additions & 3 deletions bson/son.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,17 +177,17 @@ def get( # type: ignore[override]
except KeyError:
return default

def __eq__(self, other: Any) -> bool:
def __eq__(self, other: object) -> bool:
Comment thread
Copilot marked this conversation as resolved.
Resolved
"""Comparison to another SON is order-sensitive while comparison to a
regular dictionary is order-insensitive.
"""
if isinstance(other, SON):
return len(self) == len(other) and list(self.items()) == list(other.items())
return cast(bool, self.to_dict() == other)
return self.to_dict() == other

__hash__ = None

def __ne__(self, other: Any) -> bool:
def __ne__(self, other: object) -> bool:
return not self == other

def __len__(self) -> int:
Expand Down
4 changes: 2 additions & 2 deletions bson/timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def inc(self) -> int:
"""Get the inc portion of this :class:`Timestamp`."""
return self.__inc

def __eq__(self, other: Any) -> bool:
def __eq__(self, other: object) -> bool:
if isinstance(other, Timestamp):
return self.__time == other.time and self.__inc == other.inc
else:
Expand All @@ -89,7 +89,7 @@ def __eq__(self, other: Any) -> bool:
def __hash__(self) -> int:
return hash(self.time) ^ hash(self.inc)

def __ne__(self, other: Any) -> bool:
def __ne__(self, other: object) -> bool:
return not self == other

def __lt__(self, other: Any) -> bool:
Expand Down
2 changes: 1 addition & 1 deletion pymongo/asynchronous/auth_oidc.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ async def _authenticate_human(self, conn: AsyncConnection) -> Mapping[str, Any]

async def _get_access_token(self) -> str | None:
properties = self.properties
cb: None | OIDCCallback
cb: OIDCCallback | None
resp: OIDCCallbackResult

is_human = properties.human_callback is not None
Expand Down
4 changes: 2 additions & 2 deletions pymongo/asynchronous/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,12 +294,12 @@ def __getitem__(self, name: str) -> AsyncCollection[_DocumentType]:
def __repr__(self) -> str:
return f"{type(self).__name__}({self._database!r}, {self._name!r})"

def __eq__(self, other: Any) -> bool:
def __eq__(self, other: object) -> bool:
if isinstance(other, AsyncCollection):
return self._database == other.database and self._name == other.name
return NotImplemented

def __ne__(self, other: Any) -> bool:
def __ne__(self, other: object) -> bool:
return not self == other

def __hash__(self) -> int:
Expand Down
4 changes: 2 additions & 2 deletions pymongo/asynchronous/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,12 @@ def with_options(
read_concern or self.read_concern,
)

def __eq__(self, other: Any) -> bool:
def __eq__(self, other: object) -> bool:
if isinstance(other, AsyncDatabase):
return self._client == other.client and self._name == other.name
return NotImplemented

def __ne__(self, other: Any) -> bool:
def __ne__(self, other: object) -> bool:
return not self == other

def __hash__(self) -> int:
Expand Down
4 changes: 2 additions & 2 deletions pymongo/asynchronous/mongo_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1385,12 +1385,12 @@ def eq_props(self) -> tuple[tuple[_Address, ...], str | None, str | None, str]:
self._resolve_srv_info["srv_service_name"],
)

def __eq__(self, other: Any) -> bool:
def __eq__(self, other: object) -> bool:
if isinstance(other, self.__class__):
return self.eq_props() == other.eq_props()
return NotImplemented

def __ne__(self, other: Any) -> bool:
def __ne__(self, other: object) -> bool:
return not self == other

def __hash__(self) -> int:
Expand Down
4 changes: 2 additions & 2 deletions pymongo/collation.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,14 +207,14 @@ def __repr__(self) -> str:
document = self.document
return "Collation({})".format(", ".join(f"{key}={document[key]!r}" for key in document))

def __eq__(self, other: Any) -> bool:
def __eq__(self, other: object) -> bool:
if isinstance(other, Collation):
return self.document == other.document
return NotImplemented

__hash__ = None # type: ignore[assignment]

def __ne__(self, other: Any) -> bool:
def __ne__(self, other: object) -> bool:
return not self == other


Expand Down
4 changes: 2 additions & 2 deletions pymongo/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ def validate_auth_mechanism_properties(option: str, value: Any) -> dict[str, boo

def validate_document_class(
option: str, value: Any
) -> type[MutableMapping[str, Any]] | type[RawBSONDocument]:
) -> type[MutableMapping[str, Any] | RawBSONDocument]:
"""Validate the document_class option."""
# Generic aliases like SON[str, Any] or dict[str, Any] aren't classes, so
# resolve to their origin before the subclass check. issubclass() raises
Expand Down Expand Up @@ -1041,7 +1041,7 @@ def __delitem__(self, key: str) -> None:
del self.__casedkeys[lc_key]
del self.__data[lc_key]

def __eq__(self, other: Any) -> bool:
def __eq__(self, other: object) -> bool:
if not isinstance(other, abc.Mapping):
return NotImplemented
if len(self) != len(other):
Expand Down
6 changes: 2 additions & 4 deletions pymongo/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -754,8 +754,7 @@ def _client_construct_op_msg(
buf.write(b"\x00\x00\x00\x00")
buf.write(b"ops\x00")
# Write all the ops documents
for op_encoded in to_send_ops_encoded:
buf.write(op_encoded)
buf.writelines(to_send_ops_encoded)
resume_location = buf.tell()
# Write type 1 section size
length = buf.tell()
Expand All @@ -770,8 +769,7 @@ def _client_construct_op_msg(
buf.write(b"\x00\x00\x00\x00")
buf.write(b"nsInfo\x00")
# Write all the nsInfo documents
for ns_encoded in to_send_ns_encoded:
buf.write(ns_encoded)
buf.writelines(to_send_ns_encoded)
# Write type 1 section size
length = buf.tell()
buf.seek(size_location)
Expand Down
Loading
Loading