Skip to content

Commit 0d658b3

Browse files
committed
Revert "PYTHON-2504 Run ruff --fix-only --select ALL --fixable ALL --target-version py37 --line-length=100 --unfixable COM812,D400,D415,ERA001,RUF100,SIM108,D211,D212,SIM105,SIM bson/*.py pymongo/*.py gridfs/*.py test/*.py test/*/*.py"
This reverts commit 5774406.
1 parent 5774406 commit 0d658b3

File tree

164 files changed

+5408
-5050
lines changed

Some content is hidden

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

164 files changed

+5408
-5050
lines changed

bson/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,8 @@ def get_data_and_view(data: Any) -> Tuple[Any, memoryview]:
237237
def _raise_unknown_type(element_type: int, element_name: str) -> NoReturn:
238238
"""Unknown type helper."""
239239
raise InvalidBSON(
240-
"Detected unknown BSON type {!r} for fieldname '{}'. Are "
241-
"you using the latest driver version?".format(chr(element_type).encode(), element_name)
240+
"Detected unknown BSON type %r for fieldname '%s'. Are "
241+
"you using the latest driver version?" % (chr(element_type).encode(), element_name)
242242
)
243243

244244

bson/_helpers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515
"""Setstate and getstate functions for objects with __slots__, allowing
16-
compatibility with default pickling protocol
16+
compatibility with default pickling protocol
1717
"""
1818
from typing import Any, Mapping
1919

@@ -33,7 +33,7 @@ def _mangle_name(name: str, prefix: str) -> str:
3333

3434
def _getstate_slots(self: Any) -> Mapping[Any, Any]:
3535
prefix = self.__class__.__name__
36-
ret = {}
36+
ret = dict()
3737
for name in self.__slots__:
3838
mangled_name = _mangle_name(name, prefix)
3939
if hasattr(self, mangled_name):

bson/binary.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,8 @@ def as_uuid(self, uuid_representation: int = UuidRepresentation.STANDARD) -> UUI
330330
return UUID(bytes=self)
331331

332332
raise ValueError(
333-
f"cannot decode subtype {self.subtype} to {UUID_REPRESENTATION_NAMES[uuid_representation]}"
333+
"cannot decode subtype %s to %s"
334+
% (self.subtype, UUID_REPRESENTATION_NAMES[uuid_representation])
334335
)
335336

336337
@property
@@ -359,5 +360,5 @@ def __hash__(self) -> int:
359360
def __ne__(self, other: Any) -> bool:
360361
return not self == other
361362

362-
def __repr__(self) -> str:
363+
def __repr__(self):
363364
return f"Binary({bytes.__repr__(self)}, {self.__subtype})"

bson/code.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
"""Tools for representing JavaScript code in BSON."""
15+
"""Tools for representing JavaScript code in BSON.
16+
"""
1617

1718
from collections.abc import Mapping as _Mapping
1819
from typing import Any, Mapping, Optional, Type, Union
@@ -86,7 +87,7 @@ def scope(self) -> Optional[Mapping[str, Any]]:
8687
"""Scope dictionary for this instance or ``None``."""
8788
return self.__scope
8889

89-
def __repr__(self) -> str:
90+
def __repr__(self):
9091
return f"Code({str.__repr__(self)}, {self.__scope!r})"
9192

9293
def __eq__(self, other: Any) -> bool:

bson/codec_options.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,12 @@ class TypeEncoder(abc.ABC):
6565
@_abstractproperty
6666
def python_type(self) -> Any:
6767
"""The Python type to be converted into something serializable."""
68+
pass
6869

6970
@abc.abstractmethod
7071
def transform_python(self, value: Any) -> Any:
7172
"""Convert the given Python object into something serializable."""
73+
pass
7274

7375

7476
class TypeDecoder(abc.ABC):
@@ -84,10 +86,12 @@ class TypeDecoder(abc.ABC):
8486
@_abstractproperty
8587
def bson_type(self) -> Any:
8688
"""The BSON type to be converted into our own type."""
89+
pass
8790

8891
@abc.abstractmethod
8992
def transform_bson(self, value: Any) -> Any:
9093
"""Convert the given BSON value into our own type."""
94+
pass
9195

9296

9397
class TypeCodec(TypeEncoder, TypeDecoder):
@@ -103,6 +107,8 @@ class TypeCodec(TypeEncoder, TypeDecoder):
103107
See :ref:`custom-type-type-codec` documentation for an example.
104108
"""
105109

110+
pass
111+
106112

107113
_Codec = Union[TypeEncoder, TypeDecoder, TypeCodec]
108114
_Fallback = Callable[[Any], Any]
@@ -161,7 +167,8 @@ def __init__(
161167
self._decoder_map[codec.bson_type] = codec.transform_bson
162168
if not is_valid_codec:
163169
raise TypeError(
164-
f"Expected an instance of {TypeEncoder.__name__}, {TypeDecoder.__name__}, or {TypeCodec.__name__}, got {codec!r} instead"
170+
"Expected an instance of %s, %s, or %s, got %r instead"
171+
% (TypeEncoder.__name__, TypeDecoder.__name__, TypeCodec.__name__, codec)
165172
)
166173

167174
def _validate_type_encoder(self, codec: _Codec) -> None:
@@ -171,11 +178,11 @@ def _validate_type_encoder(self, codec: _Codec) -> None:
171178
if issubclass(cast(TypeCodec, codec).python_type, pytype):
172179
err_msg = (
173180
"TypeEncoders cannot change how built-in types are "
174-
"encoded (encoder {} transforms type {})".format(codec, pytype)
181+
"encoded (encoder %s transforms type %s)" % (codec, pytype)
175182
)
176183
raise TypeError(err_msg)
177184

178-
def __repr__(self) -> str:
185+
def __repr__(self):
179186
return "{}(type_codecs={!r}, fallback_encoder={!r})".format(
180187
self.__class__.__name__,
181188
self.__type_codecs,
@@ -240,7 +247,7 @@ class _BaseCodecOptions(NamedTuple):
240247
class CodecOptions(_BaseCodecOptions):
241248
"""Encapsulates options used encoding and / or decoding BSON."""
242249

243-
def __init__(self, *args, **kwargs) -> None:
250+
def __init__(self, *args, **kwargs):
244251
"""Encapsulates options used encoding and / or decoding BSON.
245252
246253
The `document_class` option is used to define a custom type for use
@@ -391,9 +398,10 @@ def _arguments_repr(self) -> str:
391398
)
392399

393400
return (
394-
"document_class={}, tz_aware={!r}, uuid_representation={}, "
395-
"unicode_decode_error_handler={!r}, tzinfo={!r}, "
396-
"type_registry={!r}, datetime_conversion={}".format(
401+
"document_class=%s, tz_aware=%r, uuid_representation=%s, "
402+
"unicode_decode_error_handler=%r, tzinfo=%r, "
403+
"type_registry=%r, datetime_conversion=%s"
404+
% (
397405
document_class_repr,
398406
self.tz_aware,
399407
uuid_rep_repr,
@@ -417,7 +425,7 @@ def _options_dict(self) -> Dict[str, Any]:
417425
"datetime_conversion": self.datetime_conversion,
418426
}
419427

420-
def __repr__(self) -> str:
428+
def __repr__(self):
421429
return f"{self.__class__.__name__}({self._arguments_repr()})"
422430

423431
def with_options(self, **kwargs: Any) -> "CodecOptions":

bson/datetime_ms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class DatetimeMS:
3434

3535
__slots__ = ("_value",)
3636

37-
def __init__(self, value: Union[int, datetime.datetime]) -> None:
37+
def __init__(self, value: Union[int, datetime.datetime]):
3838
"""Represents a BSON UTC datetime.
3939
4040
BSON UTC datetimes are defined as an int64 of milliseconds since the

bson/dbref.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def as_doc(self) -> SON[str, Any]:
101101
doc.update(self.__kwargs)
102102
return doc
103103

104-
def __repr__(self) -> str:
104+
def __repr__(self):
105105
extra = "".join([f", {k}={v!r}" for k, v in self.__kwargs.items()])
106106
if self.database is None:
107107
return f"DBRef({self.collection!r}, {self.id!r}{extra})"

bson/decimal128.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ def __str__(self) -> str:
296296
return "NaN"
297297
return str(dec)
298298

299-
def __repr__(self) -> str:
299+
def __repr__(self):
300300
return f"Decimal128('{str(self)}')"
301301

302302
def __setstate__(self, value: Tuple[int, int]) -> None:

bson/json_util.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ class JSONOptions(CodecOptions):
224224
datetime_representation: int
225225
strict_uuid: bool
226226

227-
def __init__(self, *args, **kwargs) -> None:
227+
def __init__(self, *args, **kwargs):
228228
"""Encapsulates JSON options for :func:`dumps` and :func:`loads`.
229229
230230
:Parameters:
@@ -350,9 +350,10 @@ def __new__(
350350

351351
def _arguments_repr(self) -> str:
352352
return (
353-
"strict_number_long={!r}, "
354-
"datetime_representation={!r}, "
355-
"strict_uuid={!r}, json_mode={!r}, {}".format(
353+
"strict_number_long=%r, "
354+
"datetime_representation=%r, "
355+
"strict_uuid=%r, json_mode=%r, %s"
356+
% (
356357
self.strict_number_long,
357358
self.datetime_representation,
358359
self.strict_uuid,
@@ -491,7 +492,7 @@ def _json_convert(obj: Any, json_options: JSONOptions = DEFAULT_JSON_OPTIONS) ->
491492
if hasattr(obj, "items"):
492493
return SON(((k, _json_convert(v, json_options)) for k, v in obj.items()))
493494
elif hasattr(obj, "__iter__") and not isinstance(obj, (str, bytes)):
494-
return [_json_convert(v, json_options) for v in obj]
495+
return list(_json_convert(v, json_options) for v in obj)
495496
try:
496497
return default(obj, json_options)
497498
except TypeError:
@@ -719,7 +720,7 @@ def _parse_canonical_regex(doc: Any) -> Regex:
719720
if len(regex) != 2:
720721
raise TypeError(
721722
'Bad $regularExpression must include only "pattern"'
722-
'and "options" components: {}'.format(doc)
723+
'and "options" components: %s' % (doc,)
723724
)
724725
opts = regex["options"]
725726
if not isinstance(opts, str):

bson/max_key.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
"""Representation for the MongoDB internal MaxKey type."""
15+
"""Representation for the MongoDB internal MaxKey type.
16+
"""
1617
from typing import Any
1718

1819

@@ -50,5 +51,5 @@ def __ge__(self, dummy: Any) -> bool:
5051
def __gt__(self, other: Any) -> bool:
5152
return not isinstance(other, MaxKey)
5253

53-
def __repr__(self) -> str:
54+
def __repr__(self):
5455
return "MaxKey()"

bson/min_key.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
"""Representation for the MongoDB internal MinKey type."""
15+
"""Representation for the MongoDB internal MinKey type.
16+
"""
1617
from typing import Any
1718

1819

@@ -50,5 +51,5 @@ def __ge__(self, other: Any) -> bool:
5051
def __gt__(self, dummy: Any) -> bool:
5152
return False
5253

53-
def __repr__(self) -> str:
54+
def __repr__(self):
5455
return "MinKey()"

bson/objectid.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
"""Tools for working with MongoDB ObjectIds."""
15+
"""Tools for working with MongoDB ObjectIds.
16+
"""
1617

1718
import binascii
1819
import calendar
@@ -165,6 +166,7 @@ def _random(cls) -> bytes:
165166

166167
def __generate(self) -> None:
167168
"""Generate a new value for this ObjectId."""
169+
168170
# 4 bytes current time
169171
oid = struct.pack(">I", int(time.time()))
170172

@@ -220,13 +222,13 @@ def generation_time(self) -> datetime.datetime:
220222
return datetime.datetime.fromtimestamp(timestamp, utc)
221223

222224
def __getstate__(self) -> bytes:
223-
"""Return value of object for pickling.
225+
"""return value of object for pickling.
224226
needed explicitly because __slots__() defined.
225227
"""
226228
return self.__id
227229

228230
def __setstate__(self, value: Any) -> None:
229-
"""Explicit state set from pickling"""
231+
"""explicit state set from pickling"""
230232
# Provide backwards compatability with OIDs
231233
# pickled with pymongo-1.9 or older.
232234
if isinstance(value, dict):
@@ -244,7 +246,7 @@ def __setstate__(self, value: Any) -> None:
244246
def __str__(self) -> str:
245247
return binascii.hexlify(self.__id).decode()
246248

247-
def __repr__(self) -> str:
249+
def __repr__(self):
248250
return f"ObjectId('{str(self)}')"
249251

250252
def __eq__(self, other: Any) -> bool:

bson/raw_bson.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ class from the standard library so it can be used like a read-only
131131
elif not issubclass(codec_options.document_class, RawBSONDocument):
132132
raise TypeError(
133133
"RawBSONDocument cannot use CodecOptions with document "
134-
"class {}".format(codec_options.document_class)
134+
"class %s" % (codec_options.document_class,)
135135
)
136136
self.__codec_options = codec_options
137137
# Validate the bson object size.
@@ -173,7 +173,7 @@ def __eq__(self, other: Any) -> bool:
173173
return self.__raw == other.raw
174174
return NotImplemented
175175

176-
def __repr__(self) -> str:
176+
def __repr__(self):
177177
return "{}({!r}, codec_options={!r})".format(
178178
self.__class__.__name__,
179179
self.raw,

bson/regex.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
"""Tools for representing MongoDB regular expressions."""
15+
"""Tools for representing MongoDB regular expressions.
16+
"""
1617

1718
import re
1819
from typing import Any, Generic, Pattern, Type, TypeVar, Union
@@ -115,7 +116,7 @@ def __eq__(self, other: Any) -> bool:
115116
def __ne__(self, other: Any) -> bool:
116117
return not self == other
117118

118-
def __repr__(self) -> str:
119+
def __repr__(self):
119120
return f"Regex({self.pattern!r}, {self.flags!r})"
120121

121122
def try_compile(self) -> "Pattern[_T]":

bson/son.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
1717
Regular dictionaries can be used instead of SON objects, but not when the order
1818
of keys is important. A SON object can be used just like a normal Python
19-
dictionary.
20-
"""
19+
dictionary."""
2120

2221
import copy
2322
import re
@@ -71,7 +70,7 @@ def __new__(cls: Type["SON[_Key, _Value]"], *args: Any, **kwargs: Any) -> "SON[_
7170
instance.__keys = []
7271
return instance
7372

74-
def __repr__(self) -> str:
73+
def __repr__(self):
7574
result = []
7675
for key in self.__keys:
7776
result.append(f"({key!r}, {self[key]!r})")

bson/timestamp.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
"""Tools for representing MongoDB internal Timestamps."""
15+
"""Tools for representing MongoDB internal Timestamps.
16+
"""
1617

1718
import calendar
1819
import datetime
@@ -111,7 +112,7 @@ def __ge__(self, other: Any) -> bool:
111112
return (self.time, self.inc) >= (other.time, other.inc)
112113
return NotImplemented
113114

114-
def __repr__(self) -> str:
115+
def __repr__(self):
115116
return f"Timestamp({self.__time}, {self.__inc})"
116117

117118
def as_datetime(self) -> datetime.datetime:

gridfs/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
class GridFS:
5757
"""An instance of GridFS on top of a single Database."""
5858

59-
def __init__(self, database: Database, collection: str = "fs") -> None:
59+
def __init__(self, database: Database, collection: str = "fs"):
6060
"""Create a new instance of :class:`GridFS`.
6161
6262
Raises :class:`TypeError` if `database` is not an instance of
@@ -141,6 +141,7 @@ def put(self, data: Any, **kwargs: Any) -> Any:
141141
.. versionchanged:: 3.0
142142
w=0 writes to GridFS are now prohibited.
143143
"""
144+
144145
with GridIn(self.__collection, **kwargs) as grid_file:
145146
grid_file.write(data)
146147
return grid_file._id

0 commit comments

Comments
 (0)