Skip to content

Commit 2a52f3f

Browse files
authored
Removing dependency on six (#1676)
1 parent 599f5a9 commit 2a52f3f

File tree

8 files changed

+17
-36
lines changed

8 files changed

+17
-36
lines changed

redis/commands/search/_util.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
import six
2-
3-
41
def to_string(s):
5-
if isinstance(s, six.string_types):
2+
if isinstance(s, str):
63
return s
7-
elif isinstance(s, six.binary_type):
4+
elif isinstance(s, bytes):
85
return s.decode("utf-8", "ignore")
96
else:
107
return s # Not a string we care about

redis/commands/search/aggregation.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from six import string_types
2-
31
FIELDNAME = object()
42

53

@@ -93,7 +91,7 @@ def __init__(self, fields, reducers):
9391
if not reducers:
9492
raise ValueError("Need at least one reducer")
9593

96-
fields = [fields] if isinstance(fields, string_types) else fields
94+
fields = [fields] if isinstance(fields, str) else fields
9795
reducers = [reducers] if isinstance(reducers, Reducer) else reducers
9896

9997
self.fields = fields
@@ -299,7 +297,7 @@ def sort_by(self, *fields, **kwargs):
299297
.sort_by(Desc("@paid"), max=10)
300298
```
301299
"""
302-
if isinstance(fields, (string_types, SortDirection)):
300+
if isinstance(fields, (str, SortDirection)):
303301
fields = [fields]
304302

305303
max = kwargs.get("max", 0)
@@ -318,7 +316,7 @@ def filter(self, expressions):
318316
- **fields**: Fields to group by. This can either be a single string,
319317
or a list of strings.
320318
"""
321-
if isinstance(expressions, string_types):
319+
if isinstance(expressions, str):
322320
expressions = [expressions]
323321

324322
for expression in expressions:

redis/commands/search/commands.py

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import itertools
22
import time
3-
import six
43

54
from .document import Document
65
from .result import Result
@@ -308,9 +307,8 @@ def load_document(self, id):
308307
Load a single document by id
309308
"""
310309
fields = self.client.hgetall(id)
311-
if six.PY3:
312-
f2 = {to_string(k): to_string(v) for k, v in fields.items()}
313-
fields = f2
310+
f2 = {to_string(k): to_string(v) for k, v in fields.items()}
311+
fields = f2
314312

315313
try:
316314
del fields["id"]
@@ -337,13 +335,13 @@ def info(self):
337335
"""
338336

339337
res = self.client.execute_command(INFO_CMD, self.index_name)
340-
it = six.moves.map(to_string, res)
341-
return dict(six.moves.zip(it, it))
338+
it = map(to_string, res)
339+
return dict(zip(it, it))
342340

343341
def _mk_query_args(self, query):
344342
args = [self.index_name]
345343

346-
if isinstance(query, six.string_types):
344+
if isinstance(query, str):
347345
# convert the query from a text to a query object
348346
query = Query(query)
349347
if not isinstance(query, Query):
@@ -448,7 +446,7 @@ def spellcheck(self, query, distance=None, include=None, exclude=None):
448446
return corrections
449447

450448
for _correction in raw:
451-
if isinstance(_correction, six.integer_types) and _correction == 0:
449+
if isinstance(_correction, int) and _correction == 0:
452450
continue
453451

454452
if len(_correction) != 3:

redis/commands/search/document.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import six
2-
3-
41
class Document(object):
52
"""
63
Represents a single document in a result set
@@ -9,7 +6,7 @@ class Document(object):
96
def __init__(self, id, payload=None, **fields):
107
self.id = id
118
self.payload = payload
12-
for k, v in six.iteritems(fields):
9+
for k, v in fields.items():
1310
setattr(self, k, v)
1411

1512
def __repr__(self):

redis/commands/search/query.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import six
2-
3-
41
class Query(object):
52
"""
63
Query is used to build complex queries that have more parameters than just
@@ -66,7 +63,7 @@ def _mk_field_list(self, fields):
6663
if not fields:
6764
return []
6865
return \
69-
[fields] if isinstance(fields, six.string_types) else list(fields)
66+
[fields] if isinstance(fields, str) else list(fields)
7067

7168
def summarize(self, fields=None, context_len=None,
7269
num_frags=None, sep=None):

redis/commands/search/querystring.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
from six import string_types, integer_types
2-
3-
41
def tags(*t):
52
"""
63
Indicate that the values should be matched to a tag field
@@ -186,7 +183,7 @@ def __init__(self, *children, **kwparams):
186183
kvparams = {}
187184
for k, v in kwparams.items():
188185
curvals = kvparams.setdefault(k, [])
189-
if isinstance(v, (string_types, integer_types, float)):
186+
if isinstance(v, (str, int, float)):
190187
curvals.append(Value.make_value(v))
191188
elif isinstance(v, Value):
192189
curvals.append(v)

redis/commands/search/result.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from six.moves import xrange, zip as izip
2-
31
from .document import Document
42
from ._util import to_string
53

@@ -32,7 +30,7 @@ def __init__(
3230

3331
offset = 2 if with_scores else 1
3432

35-
for i in xrange(1, len(res), step):
33+
for i in range(1, len(res), step):
3634
id = to_string(res[i])
3735
payload = to_string(res[i + offset]) if has_payload else None
3836
# fields_offset = 2 if has_payload else 1
@@ -44,7 +42,7 @@ def __init__(
4442
fields = (
4543
dict(
4644
dict(
47-
izip(
45+
zip(
4846
map(to_string, res[i + fields_offset][::2]),
4947
map(to_string, res[i + fields_offset][1::2]),
5048
)

redis/commands/search/suggestion.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from six.moves import xrange
21
from ._util import to_string
32

43

@@ -45,7 +44,7 @@ def __init__(self, with_scores, with_payloads, ret):
4544
self._sugs = ret
4645

4746
def __iter__(self):
48-
for i in xrange(0, len(self._sugs), self.sugsize):
47+
for i in range(0, len(self._sugs), self.sugsize):
4948
ss = self._sugs[i]
5049
score = float(self._sugs[i + self._scoreidx]) \
5150
if self.with_scores else 1.0

0 commit comments

Comments
 (0)