Skip to content

Commit

Permalink
Internal: Use tuple literals instead of tuple class/constructor
Browse files Browse the repository at this point in the history
See #247
  • Loading branch information
vstoykov authored and msiemens committed Dec 4, 2018
1 parent 43a0ab7 commit 0fb4233
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions tinydb/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ class Query(QueryImpl):
"""

def __init__(self):
self._path = []
self._path = ()
super(Query, self).__init__(
self._prepare_test(lambda _: True),
('path', tuple(self._path))
('path', self._path)
)

def __repr__(self):
Expand All @@ -121,8 +121,8 @@ def __hash__(self):

def __getattr__(self, item):
query = Query()
query._path = self._path + [item]
query.hashval = ('path', tuple(query._path))
query._path = self._path + (item, )
query.hashval = ('path', query._path)

return query

Expand Down Expand Up @@ -182,7 +182,7 @@ def test(value):

return self._generate_test(
lambda value: test(value),
('==', tuple(self._path), freeze(rhs))
('==', self._path, freeze(rhs))
)

def __ne__(self, rhs):
Expand All @@ -195,7 +195,7 @@ def __ne__(self, rhs):
"""
return self._generate_test(
lambda value: value != rhs,
('!=', tuple(self._path), freeze(rhs))
('!=', self._path, freeze(rhs))
)

def __lt__(self, rhs):
Expand All @@ -208,7 +208,7 @@ def __lt__(self, rhs):
"""
return self._generate_test(
lambda value: value < rhs,
('<', tuple(self._path), rhs)
('<', self._path, rhs)
)

def __le__(self, rhs):
Expand All @@ -221,7 +221,7 @@ def __le__(self, rhs):
"""
return self._generate_test(
lambda value: value <= rhs,
('<=', tuple(self._path), rhs)
('<=', self._path, rhs)
)

def __gt__(self, rhs):
Expand All @@ -234,7 +234,7 @@ def __gt__(self, rhs):
"""
return self._generate_test(
lambda value: value > rhs,
('>', tuple(self._path), rhs)
('>', self._path, rhs)
)

def __ge__(self, rhs):
Expand All @@ -247,7 +247,7 @@ def __ge__(self, rhs):
"""
return self._generate_test(
lambda value: value >= rhs,
('>=', tuple(self._path), rhs)
('>=', self._path, rhs)
)

def exists(self):
Expand All @@ -258,7 +258,7 @@ def exists(self):
"""
return self._generate_test(
lambda _: True,
('exists', tuple(self._path))
('exists', self._path)
)

def matches(self, regex, flags=0):
Expand All @@ -271,7 +271,7 @@ def matches(self, regex, flags=0):
"""
return self._generate_test(
lambda value: re.match(regex, value, flags),
('matches', tuple(self._path), regex)
('matches', self._path, regex)
)

def search(self, regex, flags=0):
Expand All @@ -285,7 +285,7 @@ def search(self, regex, flags=0):
"""
return self._generate_test(
lambda value: re.search(regex, value, flags),
('search', tuple(self._path), regex)
('search', self._path, regex)
)

def test(self, func, *args):
Expand All @@ -303,7 +303,7 @@ def test(self, func, *args):
"""
return self._generate_test(
lambda value: func(value, *args),
('test', tuple(self._path), func, args)
('test', self._path, func, args)
)

def any(self, cond):
Expand Down Expand Up @@ -338,7 +338,7 @@ def _cmp(value):

return self._generate_test(
lambda value: _cmp(value),
('any', tuple(self._path), freeze(cond))
('any', self._path, freeze(cond))
)

def all(self, cond):
Expand Down Expand Up @@ -371,7 +371,7 @@ def _cmp(value):

return self._generate_test(
lambda value: _cmp(value),
('all', tuple(self._path), freeze(cond))
('all', self._path, freeze(cond))
)

def one_of(self, items):
Expand All @@ -384,7 +384,7 @@ def one_of(self, items):
"""
return self._generate_test(
lambda value: value in items,
('one_of', tuple(self._path), freeze(items))
('one_of', self._path, freeze(items))
)


Expand Down

0 comments on commit 0fb4233

Please sign in to comment.