fix flake8 warnings

This commit is contained in:
Bastien Gerard
2020-12-08 23:52:47 +01:00
parent eabb8f60f5
commit 8a1a68ea7c
26 changed files with 110 additions and 135 deletions

View File

@@ -10,12 +10,12 @@ from mongoengine import signals
# mongoengine, e.g. instead of `from mongoengine.connection import connect`,
# users can simply use `from mongoengine import connect`, or even
# `from mongoengine import *` and then `connect('testdb')`.
from mongoengine.connection import *
from mongoengine.document import *
from mongoengine.errors import *
from mongoengine.fields import *
from mongoengine.queryset import *
from mongoengine.signals import *
from mongoengine.connection import * # noqa: F401
from mongoengine.document import * # noqa: F401
from mongoengine.errors import * # noqa: F401
from mongoengine.fields import * # noqa: F401
from mongoengine.queryset import * # noqa: F401
from mongoengine.signals import * # noqa: F401
__all__ = (

View File

@@ -180,9 +180,7 @@ class BaseList(list):
def _mark_as_changed(self, key=None):
if hasattr(self._instance, "_mark_as_changed"):
if key is not None:
self._instance._mark_as_changed(
"{}.{}".format(self._name, key % len(self))
)
self._instance._mark_as_changed(f"{self._name}.{key % len(self)}")
else:
self._instance._mark_as_changed(self._name)

View File

@@ -89,9 +89,7 @@ class BaseDocument:
list(self._fields.keys()) + ["id", "pk", "_cls", "_text_score"]
)
if _undefined_fields:
msg = ('The fields "{}" do not exist on the document "{}"').format(
_undefined_fields, self._class_name
)
msg = f'The fields "{_undefined_fields}" do not exist on the document "{self._class_name}"'
raise FieldDoesNotExist(msg)
if self.STRICT and not self._dynamic:
@@ -231,10 +229,10 @@ class BaseDocument:
setattr(self, k, data[k])
if "_fields_ordered" in data:
if self._dynamic:
setattr(self, "_fields_ordered", data["_fields_ordered"])
self._fields_ordered = data["_fields_ordered"]
else:
_super_fields_ordered = type(self)._fields_ordered
setattr(self, "_fields_ordered", _super_fields_ordered)
self._fields_ordered = _super_fields_ordered
dynamic_fields = data.get("_dynamic_fields") or SON()
for k in dynamic_fields.keys():
@@ -576,7 +574,7 @@ class BaseDocument:
else:
iterator = data.items()
for index_or_key, value in iterator:
for _index_or_key, value in iterator:
if hasattr(value, "_get_changed_fields") and not isinstance(
value, Document
): # don't follow references
@@ -999,9 +997,7 @@ class BaseDocument:
"PolygonField",
)
geo_field_types = tuple(
[_import_class(field) for field in geo_field_type_names]
)
geo_field_types = tuple(_import_class(field) for field in geo_field_type_names)
for field in cls._fields.values():
if not isinstance(field, geo_field_types):

View File

@@ -337,7 +337,7 @@ class TopLevelDocumentMetaclass(DocumentMetaclass):
# allow_inheritance to False. If the base Document allows inheritance,
# none of its subclasses can override allow_inheritance to False.
simple_class = all(
[b._meta.get("abstract") for b in flattened_bases if hasattr(b, "_meta")]
b._meta.get("abstract") for b in flattened_bases if hasattr(b, "_meta")
)
if (
not simple_class

View File

@@ -51,10 +51,10 @@ class DeReference:
doc_type = doc_type.document_type
is_list = not hasattr(items, "items")
if is_list and all([i.__class__ == doc_type for i in items]):
if is_list and all(i.__class__ == doc_type for i in items):
return items
elif not is_list and all(
[i.__class__ == doc_type for i in items.values()]
i.__class__ == doc_type for i in items.values()
):
return items
elif not field.dbref:

View File

@@ -1743,7 +1743,7 @@ class GridFSProxy:
def __str__(self):
gridout = self.get()
filename = getattr(gridout, "filename") if gridout else "<no file>"
filename = gridout.filename if gridout else "<no file>"
return f"<{self.__class__.__name__}: {filename} ({self.grid_id})>"
def __eq__(self, other):