Finalize python2/3 codebase compatibility and get rid of 2to3

This commit is contained in:
Bastien Gérard
2019-06-14 23:30:01 +02:00
parent 4d6ddb070e
commit 2ca905b6e5
11 changed files with 31 additions and 38 deletions

View File

@@ -422,10 +422,10 @@ class StrictDict(object):
return len(list(iteritems(self)))
def __eq__(self, other):
return self.items() == other.items()
return list(self.items()) == list(other.items())
def __ne__(self, other):
return self.items() != other.items()
return list(self.items()) != list(other.items())
@classmethod
def create(cls, allowed_keys):

View File

@@ -92,7 +92,7 @@ class BaseDocument(object):
# if so raise an Exception.
if not self._dynamic and (self._meta.get("strict", True) or _created):
_undefined_fields = set(values.keys()) - set(
self._fields.keys() + ["id", "pk", "_cls", "_text_score"]
list(self._fields.keys()) + ["id", "pk", "_cls", "_text_score"]
)
if _undefined_fields:
msg = ('The fields "{0}" do not exist on the document "{1}"').format(
@@ -670,7 +670,7 @@ class BaseDocument(object):
del set_data["_id"]
# Determine if any changed items were actually unset.
for path, value in set_data.items():
for path, value in list(set_data.items()):
if value or isinstance(
value, (numbers.Number, bool)
): # Account for 0 and True that are truthy

View File

@@ -8,6 +8,7 @@ import uuid
from operator import itemgetter
from bson import Binary, DBRef, ObjectId, SON
from bson.int64 import Int64
import gridfs
import pymongo
from pymongo import ReturnDocument
@@ -21,11 +22,6 @@ except ImportError:
else:
import dateutil.parser
try:
from bson.int64 import Int64
except ImportError:
Int64 = long
from mongoengine.base import (
BaseDocument,
@@ -53,8 +49,6 @@ except ImportError:
ImageOps = None
if six.PY3:
# Useless as long as 2to3 gets executed
# as it turns `long` into `int` blindly
long = int

View File

@@ -989,7 +989,7 @@ class BaseQuerySet(object):
.. versionchanged:: 0.5 - Added subfield support
"""
fields = {f: QueryFieldList.ONLY for f in fields}
self.only_fields = fields.keys()
self.only_fields = list(fields.keys())
return self.fields(True, **fields)
def exclude(self, *fields):