Skip to content

Commit be12c4a

Browse files
committed
PYTHON-5964 Adopt ruff 0.17 default rule set in addition to existing rule sets
1 parent bc683fc commit be12c4a

43 files changed

Lines changed: 138 additions & 120 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.evergreen/scripts/setup_tests.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def get_distro() -> Distro:
7171
version_id = ""
7272
arch = platform.machine()
7373
with open("/etc/os-release") as fid:
74-
for line in fid.readlines():
74+
for line in fid:
7575
line = line.replace('"', "") # noqa: PLW2901
7676
if line.startswith("NAME="):
7777
_, _, name = line.strip().partition("=")

‎.evergreen/scripts/utils.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ def handle_env_overrides(parser: argparse.ArgumentParser, opts: argparse.Namespa
281281
def read_env(path: Path | str) -> dict[str, str]:
282282
config = dict()
283283
with Path(path).open() as fid:
284-
for line in fid.readlines():
284+
for line in fid:
285285
if "=" not in line:
286286
continue
287287
name, _, value = line.strip().partition("=")

‎bson/binary.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ def __init__(
260260
def __repr__(self) -> str:
261261
return f"BinaryVector(dtype={self.dtype}, padding={self.padding}, data={self.data})"
262262

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

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

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

665665
def __repr__(self) -> str:

‎bson/code.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,12 @@ def scope(self) -> Mapping[str, Any] | None:
9191
def __repr__(self) -> str:
9292
return f"Code({str.__repr__(self)}, {self.__scope!r})"
9393

94-
def __eq__(self, other: Any) -> bool:
94+
def __eq__(self, other: object) -> bool:
9595
if isinstance(other, Code):
9696
return (self.__scope, str(self)) == (other.__scope, str(other))
9797
return False
9898

9999
__hash__: Any = None
100100

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

‎bson/codec_options.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def _validate_type_encoder(self, codec: _Codec) -> None:
183183
def __repr__(self) -> str:
184184
return f"{self.__class__.__name__}(type_codecs={self.__type_codecs!r}, fallback_encoder={self._fallback_encoder!r})"
185185

186-
def __eq__(self, other: Any) -> Any:
186+
def __eq__(self, other: object) -> Any:
187187
if not isinstance(other, type(self)):
188188
return NotImplemented
189189
return (

‎bson/datetime_ms.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ def __lt__(self, other: DatetimeMS | int) -> bool:
8080
def __le__(self, other: DatetimeMS | int) -> bool:
8181
return self._value <= other
8282

83-
def __eq__(self, other: Any) -> bool:
83+
def __eq__(self, other: object) -> bool:
8484
if isinstance(other, DatetimeMS):
8585
return self._value == other._value
8686
return False
8787

88-
def __ne__(self, other: Any) -> bool:
88+
def __ne__(self, other: object) -> bool:
8989
if isinstance(other, DatetimeMS):
9090
return self._value != other._value
9191
return True

‎bson/dbref.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,14 @@ def __repr__(self) -> str:
109109
return f"DBRef({self.collection!r}, {self.id!r}{extra})"
110110
return f"DBRef({self.collection!r}, {self.id!r}, {self.database!r}{extra})"
111111

112-
def __eq__(self, other: Any) -> bool:
112+
def __eq__(self, other: object) -> bool:
113113
if isinstance(other, DBRef):
114114
us = (self.__database, self.__collection, self.__id, self.__kwargs)
115115
them = (other.__database, other.__collection, other.__id, other.__kwargs)
116116
return us == them
117117
return NotImplemented
118118

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

122122
def __hash__(self) -> int:

‎bson/decimal128.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,12 +350,12 @@ def __setstate__(self, value: tuple[int, int]) -> None:
350350
def __getstate__(self) -> tuple[int, int]:
351351
return self.__high, self.__low
352352

353-
def __eq__(self, other: Any) -> bool:
353+
def __eq__(self, other: object) -> bool:
354354
if isinstance(other, Decimal128):
355355
return self.bid == other.bid
356356
return NotImplemented
357357

358358
__hash__ = None # type: ignore[assignment]
359359

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

‎bson/json_util.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,12 @@
140140
from bson.tz_util import utc
141141

142142
_RE_OPT_TABLE = {
143-
"i": re.I,
144-
"l": re.L,
145-
"m": re.M,
146-
"s": re.S,
147-
"u": re.U,
148-
"x": re.X,
143+
"i": re.IGNORECASE,
144+
"l": re.LOCALE,
145+
"m": re.MULTILINE,
146+
"s": re.DOTALL,
147+
"u": re.UNICODE,
148+
"x": re.VERBOSE,
149149
}
150150

151151

‎bson/max_key.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ def __getstate__(self) -> Any:
3232
def __setstate__(self, state: Any) -> None:
3333
pass
3434

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

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

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

4444
def __le__(self, other: Any) -> bool:

0 commit comments

Comments
 (0)