Skip to content

Commit

Permalink
Get rid of an own to_dict and own JsonEncoder in favour of `espri…
Browse files Browse the repository at this point in the history
…ma.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 )
  • Loading branch information
KOLANICH committed Mar 1, 2023
1 parent 530f496 commit 06c9bbe
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 85 deletions.
16 changes: 3 additions & 13 deletions opener/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,13 @@


def _import():
global to_dict, transform
from .to_dict import to_dict
global transform
from .transformations import transform
global esprima, pkg_resources
import esprima
import pkg_resources


class JsonEncoder(json.JSONEncoder):
def default(self, obj):
# Regex patterns aren't JSON-serializable, but escodegen shouldn't
# need them.
if isinstance(obj, re.Pattern):
return "THIS_SHOULD_NOT_APPEAR_IN_GENERATED_CODE!"
return super().default(obj)


def usage(*, exit: bool, error: bool):
print(USAGE, end="", file=(sys.stderr if error else sys.stdout))
if exit:
Expand Down Expand Up @@ -126,12 +116,12 @@ def main():

if verbose:
print("Making AST JSON-serializable...", file=sys.stderr)
ast_dict = to_dict(ast)
ast_dict = esprima.toDict(ast)

if emit_ast:
if verbose:
print("Printing AST...", file=sys.stderr)
json.dump(ast_dict, sys.stdout, cls=JsonEncoder)
json.dump(ast_dict, sys.stdout)
else:
if verbose:
print("Formatting code...", file=sys.stderr)
Expand Down
72 changes: 0 additions & 72 deletions opener/to_dict.py

This file was deleted.

0 comments on commit 06c9bbe

Please sign in to comment.