Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove hy.disassemble #2577

Merged
merged 1 commit into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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