Skip to content

Commit

Permalink
Rename Query.path to Query._path
Browse files Browse the repository at this point in the history
To avoid problems when having a dict element named `path`.
  • Loading branch information
joshuahhh authored and msiemens committed Jun 27, 2016
1 parent 4378900 commit 8c3eeec
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 @@ -105,12 +105,12 @@ class Query(object):

def __init__(self, path=None):
if path is None:
self.path = []
self._path = []
else:
self.path = path
self._path = path

def __getattr__(self, item):
return Query(self.path + [item])
return Query(self._path + [item])

__getitem__ = __getattr__

Expand All @@ -122,13 +122,13 @@ def _generate_test(self, test, hashval):
:param hashval: The hash of the query.
:return: A :class:`~tinydb.queries.QueryImpl` object
"""
if not self.path:
if not self._path:
raise ValueError('Query has no path')

def impl(value):
try:
# Resolve the path
for part in self.path:
for part in self._path:
value = value[part]
except (KeyError, TypeError):
return False
Expand Down Expand Up @@ -164,7 +164,7 @@ def test(value):
return value == rhs

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

def __ne__(self, rhs):
"""
Expand All @@ -175,7 +175,7 @@ def __ne__(self, rhs):
:param rhs: The value to compare against
"""
return self._generate_test(lambda value: value != rhs,
('!=', tuple(self.path), freeze(rhs)))
('!=', tuple(self._path), freeze(rhs)))

def __lt__(self, rhs):
"""
Expand All @@ -186,7 +186,7 @@ def __lt__(self, rhs):
:param rhs: The value to compare against
"""
return self._generate_test(lambda value: value < rhs,
('<', tuple(self.path), rhs))
('<', tuple(self._path), rhs))

def __le__(self, rhs):
"""
Expand All @@ -197,7 +197,7 @@ def __le__(self, rhs):
:param rhs: The value to compare against
"""
return self._generate_test(lambda value: value <= rhs,
('<=', tuple(self.path), rhs))
('<=', tuple(self._path), rhs))

def __gt__(self, rhs):
"""
Expand All @@ -208,7 +208,7 @@ def __gt__(self, rhs):
:param rhs: The value to compare against
"""
return self._generate_test(lambda value: value > rhs,
('>', tuple(self.path), rhs))
('>', tuple(self._path), rhs))

def __ge__(self, rhs):
"""
Expand All @@ -219,7 +219,7 @@ def __ge__(self, rhs):
:param rhs: The value to compare against
"""
return self._generate_test(lambda value: value >= rhs,
('>=', tuple(self.path), rhs))
('>=', tuple(self._path), rhs))

def exists(self):
"""
Expand All @@ -230,7 +230,7 @@ def exists(self):
:param rhs: The value to compare against
"""
return self._generate_test(lambda _: True,
('exists', tuple(self.path)))
('exists', tuple(self._path)))

def matches(self, regex):
"""
Expand All @@ -241,7 +241,7 @@ def matches(self, regex):
:param regex: The regular expression to use for matching
"""
return self._generate_test(lambda value: re.match(regex, value),
('matches', tuple(self.path), regex))
('matches', tuple(self._path), regex))

def search(self, regex):
"""
Expand All @@ -253,7 +253,7 @@ def search(self, regex):
:param regex: The regular expression to use for matching
"""
return self._generate_test(lambda value: re.search(regex, value),
('search', tuple(self.path), regex))
('search', tuple(self._path), regex))

def test(self, func, *args):
"""
Expand All @@ -269,7 +269,7 @@ def test(self, func, *args):
:param args: Additional arguments to pass to the test function
"""
return self._generate_test(lambda value: func(value, *args),
('test', tuple(self.path), func, args))
('test', tuple(self._path), func, args))

def any(self, cond):
"""
Expand Down Expand Up @@ -303,7 +303,7 @@ def _cmp(value):
return is_sequence(value) and any(e in cond for e in value)

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

def all(self, cond):
"""
Expand Down Expand Up @@ -335,7 +335,7 @@ def _cmp(value):
return is_sequence(value) and all(e in value for e in cond)

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


def where(key):
Expand Down

0 comments on commit 8c3eeec

Please sign in to comment.