Skip to content

Commit

Permalink
Merge pull request #2577 from Kodiologist/undisassemble
Browse files Browse the repository at this point in the history
Remove `hy.disassemble`
  • Loading branch information
Kodiologist committed May 2, 2024
2 parents b93147c + c343f13 commit 96ba4df
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 49 deletions.
1 change: 1 addition & 0 deletions NEWS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Unreleased

Removals
------------------------------
* `hy.disassemble` has been removed.
* `(defn/a …)` is now `(defn :async …)`.
* `(fn/a …)` is now `(fn :async …)`.
* `(with/a […] …)` is now `(with [:async …] …)`.
Expand Down
2 changes: 0 additions & 2 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1287,8 +1287,6 @@ available through the module ``hy``.
.. hy:autofunction:: hy.unmangle
.. hy:autofunction:: hy.disassemble
.. hy:autofunction:: hy.macroexpand
.. hy:autofunction:: hy.macroexpand-1
Expand Down
31 changes: 0 additions & 31 deletions hy/core/util.hy
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,6 @@
(import collections.abc [Iterable])
(import hy.compiler [HyASTCompiler calling-module])

(defn disassemble [tree [codegen False]]
"Return the python AST for a quoted Hy `tree` as a string.
If the second argument `codegen` is true, generate python code instead.
Dump the Python AST for given Hy *tree* to standard output. If *codegen*
is ``True``, the function prints Python code instead.
Examples:
::
=> (hy.disassemble '(print \"Hello World!\"))
Module(
body=[
Expr(value=Call(func=Name(id='print'), args=[Str(s='Hello World!')], keywords=[], starargs=None, kwargs=None))])
::
=> (hy.disassemble '(print \"Hello World!\") True)
print('Hello World!')
"
(import ast hy.compiler)

(setv compiled (hy.compiler.hy-compile tree (_calling-module-name) :import-stdlib False))
(if
codegen
(ast.unparse compiled)
(if hy._compat.PY3_9
(ast.dump compiled :indent 1)
(ast.dump compiled))))

(import threading [Lock])
(setv _gensym_counter 0)
(setv _gensym_lock (Lock))
Expand Down
17 changes: 1 addition & 16 deletions tests/native_tests/hy_misc.hy
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
;; Tests of `hy.gensym`, `hy.macroexpand`, `hy.macroexpand-1`,
;; `hy.disassemble`, `hy.read`, `hy.I`, and `hy.R`
;; `hy.read`, `hy.I`, and `hy.R`

(import
pytest)
Expand Down Expand Up @@ -67,21 +67,6 @@
'(mac 5 (a b)))))


(defn test-disassemble []
(import re)
(defn nos [x] (re.sub r"\s" "" x))
(assert (= (nos (hy.disassemble '(do (leaky) (leaky) (macros))))
(nos
"Module(
body=[Expr(value=Call(func=Name(id='leaky', ctx=Load()), args=[], keywords=[])),
Expr(value=Call(func=Name(id='leaky', ctx=Load()), args=[], keywords=[])),
Expr(value=Call(func=Name(id='macros', ctx=Load()), args=[], keywords=[]))],type_ignores=[])")))
(assert (= (nos (hy.disassemble '(do (leaky) (leaky) (macros)) True))
"leaky()leaky()macros()"))
(assert (= (re.sub r"[()\n ]" "" (hy.disassemble `(+ ~(+ 1 1) 40) True))
"2+40")))


(defn test-read-file-object []
(import io [StringIO])

Expand Down

0 comments on commit 96ba4df

Please sign in to comment.