get rid of six

This commit is contained in:
Bastien Gérard
2020-03-11 23:07:03 +01:00
parent 03e34299f0
commit 8086576677
28 changed files with 118 additions and 156 deletions

View File

@@ -9,8 +9,6 @@ import pymongo
import pymongo.errors
from pymongo.collection import ReturnDocument
from pymongo.common import validate_read_preference
import six
from six import iteritems
from mongoengine import signals
from mongoengine.base import get_document
@@ -252,12 +250,12 @@ class BaseQuerySet(object):
queryset = queryset.filter(*q_objs, **query)
try:
result = six.next(queryset)
result = next(queryset)
except StopIteration:
msg = "%s matching query does not exist." % queryset._document._class_name
raise queryset._document.DoesNotExist(msg)
try:
six.next(queryset)
next(queryset)
except StopIteration:
return result
@@ -1567,7 +1565,7 @@ class BaseQuerySet(object):
if self._limit == 0 or self._none:
raise StopIteration
raw_doc = six.next(self._cursor)
raw_doc = next(self._cursor)
if self._as_pymongo:
return raw_doc
@@ -1812,13 +1810,13 @@ class BaseQuerySet(object):
}
"""
total, data, types = self.exec_js(freq_func, field)
values = {types.get(k): int(v) for k, v in iteritems(data)}
values = {types.get(k): int(v) for k, v in data.items()}
if normalize:
values = {k: float(v) / total for k, v in values.items()}
frequencies = {}
for k, v in iteritems(values):
for k, v in values.items():
if isinstance(k, float):
if int(k) == k:
k = int(k)

View File

@@ -1,5 +1,3 @@
import six
from mongoengine.errors import OperationError
from mongoengine.queryset.base import (
BaseQuerySet,
@@ -127,8 +125,8 @@ class QuerySet(BaseQuerySet):
# Pull in ITER_CHUNK_SIZE docs from the database and store them in
# the result cache.
try:
for _ in six.moves.range(ITER_CHUNK_SIZE):
self._result_cache.append(six.next(self))
for _ in range(ITER_CHUNK_SIZE):
self._result_cache.append(next(self))
except StopIteration:
# Getting this exception means there are no more docs in the
# db cursor. Set _has_more to False so that we can use that
@@ -180,9 +178,9 @@ class QuerySetNoCache(BaseQuerySet):
return ".. queryset mid-iteration .."
data = []
for _ in six.moves.range(REPR_OUTPUT_SIZE + 1):
for _ in range(REPR_OUTPUT_SIZE + 1):
try:
data.append(six.next(self))
data.append(next(self))
except StopIteration:
break

View File

@@ -3,8 +3,6 @@ from collections import defaultdict
from bson import ObjectId, SON
from bson.dbref import DBRef
import pymongo
import six
from six import iteritems
from mongoengine.base import UPDATE_OPERATORS
from mongoengine.common import _import_class
@@ -180,7 +178,7 @@ def query(_doc_cls=None, **kwargs):
"$near" in value_dict or "$nearSphere" in value_dict
):
value_son = SON()
for k, v in iteritems(value_dict):
for k, v in value_dict.items():
if k == "$maxDistance" or k == "$minDistance":
continue
value_son[k] = v