Skip to content

Removing dependency on six #1676

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions redis/commands/search/_util.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import six


def to_string(s):
if isinstance(s, six.string_types):
if isinstance(s, str):
return s
elif isinstance(s, six.binary_type):
elif isinstance(s, bytes):
return s.decode("utf-8", "ignore")
else:
return s # Not a string we care about
8 changes: 3 additions & 5 deletions redis/commands/search/aggregation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from six import string_types

FIELDNAME = object()


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

fields = [fields] if isinstance(fields, string_types) else fields
fields = [fields] if isinstance(fields, str) else fields
reducers = [reducers] if isinstance(reducers, Reducer) else reducers

self.fields = fields
Expand Down Expand Up @@ -299,7 +297,7 @@ def sort_by(self, *fields, **kwargs):
.sort_by(Desc("@paid"), max=10)
```
"""
if isinstance(fields, (string_types, SortDirection)):
if isinstance(fields, (str, SortDirection)):
fields = [fields]

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

for expression in expressions:
Expand Down
14 changes: 6 additions & 8 deletions redis/commands/search/commands.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import itertools
import time
import six

from .document import Document
from .result import Result
Expand Down Expand Up @@ -308,9 +307,8 @@ def load_document(self, id):
Load a single document by id
"""
fields = self.client.hgetall(id)
if six.PY3:
f2 = {to_string(k): to_string(v) for k, v in fields.items()}
fields = f2
f2 = {to_string(k): to_string(v) for k, v in fields.items()}
fields = f2

try:
del fields["id"]
Expand All @@ -337,13 +335,13 @@ def info(self):
"""

res = self.client.execute_command(INFO_CMD, self.index_name)
it = six.moves.map(to_string, res)
return dict(six.moves.zip(it, it))
it = map(to_string, res)
return dict(zip(it, it))

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

if isinstance(query, six.string_types):
if isinstance(query, str):
# convert the query from a text to a query object
query = Query(query)
if not isinstance(query, Query):
Expand Down Expand Up @@ -448,7 +446,7 @@ def spellcheck(self, query, distance=None, include=None, exclude=None):
return corrections

for _correction in raw:
if isinstance(_correction, six.integer_types) and _correction == 0:
if isinstance(_correction, int) and _correction == 0:
continue

if len(_correction) != 3:
Expand Down
5 changes: 1 addition & 4 deletions redis/commands/search/document.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import six


class Document(object):
"""
Represents a single document in a result set
Expand All @@ -9,7 +6,7 @@ class Document(object):
def __init__(self, id, payload=None, **fields):
self.id = id
self.payload = payload
for k, v in six.iteritems(fields):
for k, v in fields.items():
setattr(self, k, v)

def __repr__(self):
Expand Down
5 changes: 1 addition & 4 deletions redis/commands/search/query.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import six


class Query(object):
"""
Query is used to build complex queries that have more parameters than just
Expand Down Expand Up @@ -66,7 +63,7 @@ def _mk_field_list(self, fields):
if not fields:
return []
return \
[fields] if isinstance(fields, six.string_types) else list(fields)
[fields] if isinstance(fields, str) else list(fields)

def summarize(self, fields=None, context_len=None,
num_frags=None, sep=None):
Expand Down
5 changes: 1 addition & 4 deletions redis/commands/search/querystring.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
from six import string_types, integer_types


def tags(*t):
"""
Indicate that the values should be matched to a tag field
Expand Down Expand Up @@ -186,7 +183,7 @@ def __init__(self, *children, **kwparams):
kvparams = {}
for k, v in kwparams.items():
curvals = kvparams.setdefault(k, [])
if isinstance(v, (string_types, integer_types, float)):
if isinstance(v, (str, int, float)):
curvals.append(Value.make_value(v))
elif isinstance(v, Value):
curvals.append(v)
Expand Down
6 changes: 2 additions & 4 deletions redis/commands/search/result.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from six.moves import xrange, zip as izip

from .document import Document
from ._util import to_string

Expand Down Expand Up @@ -32,7 +30,7 @@ def __init__(

offset = 2 if with_scores else 1

for i in xrange(1, len(res), step):
for i in range(1, len(res), step):
id = to_string(res[i])
payload = to_string(res[i + offset]) if has_payload else None
# fields_offset = 2 if has_payload else 1
Expand All @@ -44,7 +42,7 @@ def __init__(
fields = (
dict(
dict(
izip(
zip(
map(to_string, res[i + fields_offset][::2]),
map(to_string, res[i + fields_offset][1::2]),
)
Expand Down
3 changes: 1 addition & 2 deletions redis/commands/search/suggestion.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from six.moves import xrange
from ._util import to_string


Expand Down Expand Up @@ -45,7 +44,7 @@ def __init__(self, with_scores, with_payloads, ret):
self._sugs = ret

def __iter__(self):
for i in xrange(0, len(self._sugs), self.sugsize):
for i in range(0, len(self._sugs), self.sugsize):
ss = self._sugs[i]
score = float(self._sugs[i + self._scoreidx]) \
if self.with_scores else 1.0
Expand Down