Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelmior committed Jul 18, 2023
1 parent b93282a commit 0fb3230
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
5 changes: 2 additions & 3 deletions jsonpath_ng/jsonpath.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import unicode_literals, print_function, absolute_import, division, generators, nested_scopes
import logging
from itertools import * # noqa
from .exceptions import JSONPathError

# Get logger name
logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -739,7 +738,7 @@ def find(self, datum):

# Some iterators do not support slicing but we can still
# at least work for '*'
if self.start == None and self.end == None and self.step == None:
if self.start is None and self.end is None and self.step is None:
return [DatumInContext(datum.value[i], path=Index(i), context=datum) for i in range(0, len(datum.value))]
else:
return [DatumInContext(datum.value[i], path=Index(i), context=datum) for i in range(0, len(datum.value))[self.start:self.end:self.step]]
Expand All @@ -762,7 +761,7 @@ def filter(self, fn, data):
return data

def __str__(self):
if self.start == None and self.end == None and self.step == None:
if self.start is None and self.end is None and self.step is None:
return '[*]'
else:
return '[%s%s%s]' % (self.start or '',
Expand Down
5 changes: 3 additions & 2 deletions jsonpath_ng/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class JsonPathLexer(object):

def __init__(self, debug=False):
self.debug = debug
if self.__doc__ == None:
if self.__doc__ is None:
raise JsonPathLexerError('Docstrings have been removed! By design of PLY, jsonpath-rw requires docstrings. You must not use PYTHONOPTIMIZE=2 or python -OO.')

def tokenize(self, string):
Expand All @@ -31,7 +31,8 @@ def tokenize(self, string):

while True:
t = new_lexer.token()
if t is None: break
if t is None:
break
t.col = t.lexpos - new_lexer.latest_newline
yield t

Expand Down
4 changes: 3 additions & 1 deletion jsonpath_ng/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
generators,
nested_scopes,
)
import logging
import sys
import os.path

Expand Down Expand Up @@ -55,7 +56,8 @@ def parse_token_stream(self, token_iterator, start_symbol='jsonpath'):

parsing_table_module = '_'.join([module_name, start_symbol, 'parsetab'])

# And we regenerate the parse table every time; it doesn't actually take that long!
# And we regenerate the parse table every time;
# it doesn't actually take that long!
new_parser = ply.yacc.yacc(module=self,
debug=self.debug,
tabmodule = parsing_table_module,
Expand Down

0 comments on commit 0fb3230

Please sign in to comment.