Skip to content

Commit 06c9bbe

Browse files
committed
Get rid of an own to_dict and own JsonEncoder in favour of esprima.toDict (own code of stripping re.Pattern didn't work anyway, a esprima version where the bug is fixed has to be used, see Kronuz/esprima-python#24 )
1 parent 530f496 commit 06c9bbe

File tree

2 files changed

+3
-85
lines changed

2 files changed

+3
-85
lines changed

opener/__main__.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,13 @@
4040

4141

4242
def _import():
43-
global to_dict, transform
44-
from .to_dict import to_dict
43+
global transform
4544
from .transformations import transform
4645
global esprima, pkg_resources
4746
import esprima
4847
import pkg_resources
4948

5049

51-
class JsonEncoder(json.JSONEncoder):
52-
def default(self, obj):
53-
# Regex patterns aren't JSON-serializable, but escodegen shouldn't
54-
# need them.
55-
if isinstance(obj, re.Pattern):
56-
return "THIS_SHOULD_NOT_APPEAR_IN_GENERATED_CODE!"
57-
return super().default(obj)
58-
59-
6050
def usage(*, exit: bool, error: bool):
6151
print(USAGE, end="", file=(sys.stderr if error else sys.stdout))
6252
if exit:
@@ -126,12 +116,12 @@ def main():
126116

127117
if verbose:
128118
print("Making AST JSON-serializable...", file=sys.stderr)
129-
ast_dict = to_dict(ast)
119+
ast_dict = esprima.toDict(ast)
130120

131121
if emit_ast:
132122
if verbose:
133123
print("Printing AST...", file=sys.stderr)
134-
json.dump(ast_dict, sys.stdout, cls=JsonEncoder)
124+
json.dump(ast_dict, sys.stdout)
135125
else:
136126
if verbose:
137127
print("Formatting code...", file=sys.stderr)

opener/to_dict.py

Lines changed: 0 additions & 72 deletions
This file was deleted.

0 commit comments

Comments
 (0)