8000 Raise an informative error when docstrings have been stripped · joshbenner/python-jsonpath-rw@c46d04f · GitHub
[go: up one dir, main page]

Skip to content

Commit c46d04f

Browse files
committed
Raise an informative error when docstrings have been stripped
1 parent 9a05daf commit c46d04f

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
*.pyc
2+
*.pyo
23
*~
34

45
# Emacs

jsonpath_rw/lexer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ class JsonPathLexer(object):
1313

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

1719
def tokenize(self, string):
1820
'''

jsonpath_rw/parser.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,16 @@ def parse(string):
1414
return JsonPathParser().parse(string)
1515

1616
class JsonPathParser(object):
17+
'''
18+
An LALR-parser for JsonPath
19+
'''
20+
1721
tokens = JsonPathLexer.tokens
1822

1923
def __init__(self, debug=False, lexer_class=None):
24+
if self.__doc__ == None:
25+
raise Exception('Docstrings have been removed! By design of PLY, jsonpath-rw requires docstrings. You must not use PYTHONOPTIMIZE=2 or python -OO.')
26+
2027
self.debug = debug
2128
self.lexer_class = lexer_class or JsonPathLexer # Crufty but works around statefulness in PLY
2229

0 commit comments

Comments
 (0)
0