Skip to content

Commit b1d76c8

Browse files
authored
PYTHON-1834 [v4.0] Use a code formatter (#854)
1 parent 146d16b commit b1d76c8

File tree

193 files changed

+17927
-16908
lines changed

Some content is hidden

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

193 files changed

+17927
-16908
lines changed

bson/__init__.py

+128-135
Large diffs are not rendered by default.

bson/_helpers.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def _setstate_slots(self, state):
2424

2525
def _mangle_name(name, prefix):
2626
if name.startswith("__"):
27-
prefix = "_"+prefix
27+
prefix = "_" + prefix
2828
else:
2929
prefix = ""
3030
return prefix + name
@@ -36,5 +36,5 @@ def _getstate_slots(self):
3636
for name in self.__slots__:
3737
mangled_name = _mangle_name(name, prefix)
3838
if hasattr(self, mangled_name):
39-
ret[mangled_name] = getattr(self, mangled_name)
39+
ret[mangled_name] = getattr(self, mangled_name)
4040
return ret

bson/binary.py

+29-24
Original file line numberDiff line numberDiff line change
@@ -153,17 +153,20 @@ class UuidRepresentation:
153153
"""
154154

155155
ALL_UUID_SUBTYPES = (OLD_UUID_SUBTYPE, UUID_SUBTYPE)
156-
ALL_UUID_REPRESENTATIONS = (UuidRepresentation.UNSPECIFIED,
157-
UuidRepresentation.STANDARD,
158-
UuidRepresentation.PYTHON_LEGACY,
159-
UuidRepresentation.JAVA_LEGACY,
160-
UuidRepresentation.CSHARP_LEGACY)
156+
ALL_UUID_REPRESENTATIONS = (
157+
UuidRepresentation.UNSPECIFIED,
158+
UuidRepresentation.STANDARD,
159+
UuidRepresentation.PYTHON_LEGACY,
160+
UuidRepresentation.JAVA_LEGACY,
161+
UuidRepresentation.CSHARP_LEGACY,
162+
)
161163
UUID_REPRESENTATION_NAMES = {
162-
UuidRepresentation.UNSPECIFIED: 'UuidRepresentation.UNSPECIFIED',
163-
UuidRepresentation.STANDARD: 'UuidRepresentation.STANDARD',
164-
UuidRepresentation.PYTHON_LEGACY: 'UuidRepresentation.PYTHON_LEGACY',
165-
UuidRepresentation.JAVA_LEGACY: 'UuidRepresentation.JAVA_LEGACY',
166-
UuidRepresentation.CSHARP_LEGACY: 'UuidRepresentation.CSHARP_LEGACY'}
164+
UuidRepresentation.UNSPECIFIED: "UuidRepresentation.UNSPECIFIED",
165+
UuidRepresentation.STANDARD: "UuidRepresentation.STANDARD",
166+
UuidRepresentation.PYTHON_LEGACY: "UuidRepresentation.PYTHON_LEGACY",
167+
UuidRepresentation.JAVA_LEGACY: "UuidRepresentation.JAVA_LEGACY",
168+
UuidRepresentation.CSHARP_LEGACY: "UuidRepresentation.CSHARP_LEGACY",
169+
}
167170

168171
MD5_SUBTYPE = 5
169172
"""BSON binary subtype for an MD5 hash.
@@ -244,8 +247,9 @@ def from_uuid(cls, uuid, uuid_representation=UuidRepresentation.STANDARD):
244247
raise TypeError("uuid must be an instance of uuid.UUID")
245248

246249
if uuid_representation not in ALL_UUID_REPRESENTATIONS:
247-
raise ValueError("uuid_representation must be a value "
248-
"from bson.binary.UuidRepresentation")
250+
raise ValueError(
251+
"uuid_representation must be a value " "from bson.binary.UuidRepresentation"
252+
)
249253

250254
if uuid_representation == UuidRepresentation.UNSPECIFIED:
251255
raise ValueError(
@@ -254,7 +258,8 @@ def from_uuid(cls, uuid, uuid_representation=UuidRepresentation.STANDARD):
254258
"converted to bson.Binary instances using "
255259
"bson.Binary.from_uuid() or a different UuidRepresentation "
256260
"can be configured. See the documentation for "
257-
"UuidRepresentation for more information.")
261+
"UuidRepresentation for more information."
262+
)
258263

259264
subtype = OLD_UUID_SUBTYPE
260265
if uuid_representation == UuidRepresentation.PYTHON_LEGACY:
@@ -289,12 +294,12 @@ def as_uuid(self, uuid_representation=UuidRepresentation.STANDARD):
289294
.. versionadded:: 3.11
290295
"""
291296
if self.subtype not in ALL_UUID_SUBTYPES:
292-
raise ValueError("cannot decode subtype %s as a uuid" % (
293-
self.subtype,))
297+
raise ValueError("cannot decode subtype %s as a uuid" % (self.subtype,))
294298

295299
if uuid_representation not in ALL_UUID_REPRESENTATIONS:
296-
raise ValueError("uuid_representation must be a value from "
297-
"bson.binary.UuidRepresentation")
300+
raise ValueError(
301+
"uuid_representation must be a value from " "bson.binary.UuidRepresentation"
302+
)
298303

299304
if uuid_representation == UuidRepresentation.UNSPECIFIED:
300305
raise ValueError("uuid_representation cannot be UNSPECIFIED")
@@ -312,26 +317,26 @@ def as_uuid(self, uuid_representation=UuidRepresentation.STANDARD):
312317
if self.subtype == UUID_SUBTYPE:
313318
return UUID(bytes=self)
314319

315-
raise ValueError("cannot decode subtype %s to %s" % (
316-
self.subtype, UUID_REPRESENTATION_NAMES[uuid_representation]))
320+
raise ValueError(
321+
"cannot decode subtype %s to %s"
322+
% (self.subtype, UUID_REPRESENTATION_NAMES[uuid_representation])
323+
)
317324

318325
@property
319326
def subtype(self):
320-
"""Subtype of this binary data.
321-
"""
327+
"""Subtype of this binary data."""
322328
return self.__subtype
323329

324330
def __getnewargs__(self):
325331
# Work around http://bugs.python.org/issue7382
326332
data = super(Binary, self).__getnewargs__()[0]
327333
if not isinstance(data, bytes):
328-
data = data.encode('latin-1')
334+
data = data.encode("latin-1")
329335
return data, self.__subtype
330336

331337
def __eq__(self, other):
332338
if isinstance(other, Binary):
333-
return ((self.__subtype, bytes(self)) ==
334-
(other.subtype, bytes(other)))
339+
return (self.__subtype, bytes(self)) == (other.subtype, bytes(other))
335340
# We don't return NotImplemented here because if we did then
336341
# Binary("foo") == "foo" would return True, since Binary is a
337342
# subclass of str...

bson/code.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ def __new__(cls, code, scope=None, **kwargs):
7777

7878
@property
7979
def scope(self):
80-
"""Scope dictionary for this instance or ``None``.
81-
"""
80+
"""Scope dictionary for this instance or ``None``."""
8281
return self.__scope
8382

8483
def __repr__(self):

0 commit comments

Comments
 (0)