Skip to content

Commit 2a5adcf

Browse files
authored
PYTHON-1834 [v3.13] Use a code formatter (#857)
1 parent cc89650 commit 2a5adcf

File tree

186 files changed

+19427
-18373
lines changed

Some content is hidden

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

186 files changed

+19427
-18373
lines changed

bson/__init__.py

Lines changed: 136 additions & 139 deletions
Large diffs are not rendered by default.

bson/binary.py

Lines changed: 33 additions & 27 deletions
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.
@@ -238,8 +241,9 @@ def from_uuid(cls, uuid, uuid_representation=UuidRepresentation.STANDARD):
238241
raise TypeError("uuid must be an instance of uuid.UUID")
239242

240243
if uuid_representation not in ALL_UUID_REPRESENTATIONS:
241-
raise ValueError("uuid_representation must be a value "
242-
"from bson.binary.UuidRepresentation")
244+
raise ValueError(
245+
"uuid_representation must be a value " "from bson.binary.UuidRepresentation"
246+
)
243247

244248
if uuid_representation == UuidRepresentation.UNSPECIFIED:
245249
raise ValueError(
@@ -248,7 +252,8 @@ def from_uuid(cls, uuid, uuid_representation=UuidRepresentation.STANDARD):
248252
"converted to bson.Binary instances using "
249253
"bson.Binary.from_uuid() or a different UuidRepresentation "
250254
"can be configured. See the documentation for "
251-
"UuidRepresentation for more information.")
255+
"UuidRepresentation for more information."
256+
)
252257

253258
subtype = OLD_UUID_SUBTYPE
254259
if uuid_representation == UuidRepresentation.PYTHON_LEGACY:
@@ -283,12 +288,12 @@ def as_uuid(self, uuid_representation=UuidRepresentation.STANDARD):
283288
.. versionadded:: 3.11
284289
"""
285290
if self.subtype not in ALL_UUID_SUBTYPES:
286-
raise ValueError("cannot decode subtype %s as a uuid" % (
287-
self.subtype,))
291+
raise ValueError("cannot decode subtype %s as a uuid" % (self.subtype,))
288292

289293
if uuid_representation not in ALL_UUID_REPRESENTATIONS:
290-
raise ValueError("uuid_representation must be a value from "
291-
"bson.binary.UuidRepresentation")
294+
raise ValueError(
295+
"uuid_representation must be a value from " "bson.binary.UuidRepresentation"
296+
)
292297

293298
if uuid_representation == UuidRepresentation.UNSPECIFIED:
294299
raise ValueError("uuid_representation cannot be UNSPECIFIED")
@@ -306,26 +311,26 @@ def as_uuid(self, uuid_representation=UuidRepresentation.STANDARD):
306311
if self.subtype == UUID_SUBTYPE:
307312
return UUID(bytes=self)
308313

309-
raise ValueError("cannot decode subtype %s to %s" % (
310-
self.subtype, UUID_REPRESENTATION_NAMES[uuid_representation]))
314+
raise ValueError(
315+
"cannot decode subtype %s to %s"
316+
% (self.subtype, UUID_REPRESENTATION_NAMES[uuid_representation])
317+
)
311318

312319
@property
313320
def subtype(self):
314-
"""Subtype of this binary data.
315-
"""
321+
"""Subtype of this binary data."""
316322
return self.__subtype
317323

318324
def __getnewargs__(self):
319325
# Work around http://bugs.python.org/issue7382
320326
data = super(Binary, self).__getnewargs__()[0]
321327
if PY3 and not isinstance(data, bytes):
322-
data = data.encode('latin-1')
328+
data = data.encode("latin-1")
323329
return data, self.__subtype
324330

325331
def __eq__(self, other):
326332
if isinstance(other, Binary):
327-
return ((self.__subtype, bytes(self)) ==
328-
(other.subtype, bytes(other)))
333+
return (self.__subtype, bytes(self)) == (other.subtype, bytes(other))
329334
# We don't return NotImplemented here because if we did then
330335
# Binary("foo") == "foo" would return True, since Binary is a
331336
# subclass of str...
@@ -409,7 +414,9 @@ def __new__(cls, obj):
409414
"in PyMongo 4.0. Use the Binary.from_uuid() and Binary.to_uuid() "
410415
"with the appropriate UuidRepresentation to handle "
411416
"legacy-formatted UUIDs instead.",
412-
DeprecationWarning, stacklevel=2)
417+
DeprecationWarning,
418+
stacklevel=2,
419+
)
413420
if not isinstance(obj, UUID):
414421
raise TypeError("obj must be an instance of uuid.UUID")
415422
self = Binary.__new__(cls, obj.bytes, OLD_UUID_SUBTYPE)
@@ -422,8 +429,7 @@ def __getnewargs__(self):
422429

423430
@property
424431
def uuid(self):
425-
"""UUID instance wrapped by this UUIDLegacy instance.
426-
"""
432+
"""UUID instance wrapped by this UUIDLegacy instance."""
427433
return self.__uuid
428434

429435
def __repr__(self):

bson/code.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"""Tools for representing JavaScript code in BSON.
1616
"""
1717

18-
from bson.py3compat import abc, string_type, PY3, text_type
18+
from bson.py3compat import PY3, abc, string_type, text_type
1919

2020

2121
class Code(str):
@@ -50,11 +50,10 @@ class Code(str):
5050

5151
def __new__(cls, code, scope=None, **kwargs):
5252
if not isinstance(code, string_type):
53-
raise TypeError("code must be an "
54-
"instance of %s" % (string_type.__name__))
53+
raise TypeError("code must be an " "instance of %s" % (string_type.__name__))
5554

5655
if not PY3 and isinstance(code, text_type):
57-
self = str.__new__(cls, code.encode('utf8'))
56+
self = str.__new__(cls, code.encode("utf8"))
5857
else:
5958
self = str.__new__(cls, code)
6059

@@ -81,8 +80,7 @@ def __new__(cls, code, scope=None, **kwargs):
8180

8281
@property
8382
def scope(self):
84-
"""Scope dictionary for this instance or ``None``.
85-
"""
83+
"""Scope dictionary for this instance or ``None``."""
8684
return self.__scope
8785

8886
def __repr__(self):

0 commit comments

Comments
 (0)