autoformat with updated black

This commit is contained in:
Bastien Gerard
2020-12-08 23:10:07 +01:00
parent ee6ef1ff4b
commit c00a378776
33 changed files with 189 additions and 349 deletions

View File

@@ -244,8 +244,7 @@ class BaseDocument:
return iter(self._fields_ordered)
def __getitem__(self, name):
"""Dictionary-style field access, return a field's value if present.
"""
"""Dictionary-style field access, return a field's value if present."""
try:
if name in self._fields_ordered:
return getattr(self, name)
@@ -254,8 +253,7 @@ class BaseDocument:
raise KeyError(name)
def __setitem__(self, name, value):
"""Dictionary-style field access, set a field's value.
"""
"""Dictionary-style field access, set a field's value."""
# Ensure that the field exists before settings its value
if not self._dynamic and name not in self._fields:
raise KeyError(name)
@@ -617,8 +615,7 @@ class BaseDocument:
)
def _get_changed_fields(self):
"""Return a list of all fields that have explicitly been changed.
"""
"""Return a list of all fields that have explicitly been changed."""
EmbeddedDocument = _import_class("EmbeddedDocument")
ReferenceField = _import_class("ReferenceField")
GenericReferenceField = _import_class("GenericReferenceField")
@@ -750,8 +747,7 @@ class BaseDocument:
@classmethod
def _from_son(cls, son, _auto_dereference=True, created=False):
"""Create an instance of a Document (subclass) from a PyMongo SON (dict)
"""
"""Create an instance of a Document (subclass) from a PyMongo SON (dict)"""
if son and not isinstance(son, dict):
raise ValueError(
"The source SON object needs to be of type 'dict' but a '%s' was found"
@@ -800,7 +796,8 @@ class BaseDocument:
["Field '{}' - {}".format(k, v) for k, v in errors_dict.items()]
)
msg = "Invalid data to create a `{}` instance.\n{}".format(
cls._class_name, errors,
cls._class_name,
errors,
)
raise InvalidDocumentError(msg)
@@ -1165,8 +1162,7 @@ class BaseDocument:
@classmethod
def _translate_field_name(cls, field, sep="."):
"""Translate a field attribute name to a database field name.
"""
"""Translate a field attribute name to a database field name."""
parts = field.split(sep)
parts = [f.db_field for f in cls._lookup_field(parts)]
return ".".join(parts)

View File

@@ -117,8 +117,7 @@ class BaseField:
BaseField.creation_counter += 1
def __get__(self, instance, owner):
"""Descriptor for retrieving a value from a field in a document.
"""
"""Descriptor for retrieving a value from a field in a document."""
if instance is None:
# Document class being used rather than a document object
return self

View File

@@ -184,8 +184,7 @@ class query_counter:
"""
def __init__(self, alias=DEFAULT_CONNECTION_NAME):
"""Construct the query_counter
"""
"""Construct the query_counter"""
self.db = get_db(alias=alias)
self.initial_profiling_level = None
self._ctx_query_counter = 0 # number of queries issued by the context

View File

@@ -157,8 +157,7 @@ class DeReference:
return reference_map
def _fetch_objects(self, doc_type=None):
"""Fetch all references and convert to their document objects
"""
"""Fetch all references and convert to their document objects"""
object_map = {}
for collection, dbrefs in self.reference_map.items():

View File

@@ -14,8 +14,7 @@ IS_PYMONGO_GTE_37 = PYMONGO_VERSION >= _PYMONGO_37
def count_documents(
collection, filter, skip=None, limit=None, hint=None, collation=None
):
"""Pymongo>3.7 deprecates count in favour of count_documents
"""
"""Pymongo>3.7 deprecates count in favour of count_documents"""
if limit == 0:
return 0 # Pymongo raises an OperationFailure if called with limit=0

View File

@@ -189,7 +189,8 @@ class BaseQuerySet:
if queryset._scalar:
return queryset._get_scalar(
queryset._document._from_son(
queryset._cursor[key], _auto_dereference=self._auto_dereference,
queryset._cursor[key],
_auto_dereference=self._auto_dereference,
)
)
@@ -197,7 +198,8 @@ class BaseQuerySet:
return queryset._cursor[key]
return queryset._document._from_son(
queryset._cursor[key], _auto_dereference=self._auto_dereference,
queryset._cursor[key],
_auto_dereference=self._auto_dereference,
)
raise TypeError("Provide a slice or an integer index")
@@ -720,7 +722,7 @@ class BaseQuerySet:
return queryset.filter(pk=object_id).first()
def in_bulk(self, object_ids):
""""Retrieve a set of documents by their ids.
""" "Retrieve a set of documents by their ids.
:param object_ids: a list or tuple of ObjectId's
:rtype: dict of ObjectId's as keys and collection-specific
@@ -738,7 +740,8 @@ class BaseQuerySet:
else:
for doc in docs:
doc_map[doc["_id"]] = self._document._from_son(
doc, _auto_dereference=self._auto_dereference,
doc,
_auto_dereference=self._auto_dereference,
)
return doc_map
@@ -1556,8 +1559,7 @@ class BaseQuerySet:
# Iterator helpers
def __next__(self):
"""Wrap the result in a :class:`~mongoengine.Document` object.
"""
"""Wrap the result in a :class:`~mongoengine.Document` object."""
if self._none or self._empty:
raise StopIteration
@@ -1567,7 +1569,8 @@ class BaseQuerySet:
return raw_doc
doc = self._document._from_son(
raw_doc, _auto_dereference=self._auto_dereference,
raw_doc,
_auto_dereference=self._auto_dereference,
)
if self._scalar:

View File

@@ -13,17 +13,14 @@ def warn_empty_is_deprecated():
class QNodeVisitor:
"""Base visitor class for visiting Q-object nodes in a query tree.
"""
"""Base visitor class for visiting Q-object nodes in a query tree."""
def visit_combination(self, combination):
"""Called by QCombination objects.
"""
"""Called by QCombination objects."""
return combination
def visit_query(self, query):
"""Called by (New)Q objects.
"""
"""Called by (New)Q objects."""
return query
@@ -49,8 +46,7 @@ class SimplificationVisitor(QNodeVisitor):
return combination
def _query_conjunction(self, queries):
"""Merges query dicts - effectively &ing them together.
"""
"""Merges query dicts - effectively &ing them together."""
query_ops = set()
combined_query = {}
for query in queries: