From c343f13997fa0f0885acf9fda86e87e4d87a6c79 Mon Sep 17 00:00:00 2001
From: Kodi Arfer <git@arfer.net>
Date: Sun, 28 Apr 2024 13:37:14 -0400
Subject: [PATCH] Remove `hy.disassemble`

It's not general enough (e.g., it doesn't allow choosing the set of macros to use) and it's of ambiguous value. `hy` and `hy2py` are probably enough for most cases. If in the future there's demand for programmatic user access to the compiler, maybe we'll add something then.
---
 NEWS.rst                      |  1 +
 docs/api.rst                  |  2 --
 hy/core/util.hy               | 31 -------------------------------
 tests/native_tests/hy_misc.hy | 17 +----------------
 4 files changed, 2 insertions(+), 49 deletions(-)

diff --git a/NEWS.rst b/NEWS.rst
index 2b48f0ae6..05731db45 100644
--- a/NEWS.rst
+++ b/NEWS.rst
@@ -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 …] …)`.
diff --git a/docs/api.rst b/docs/api.rst
index 584ee9b4c..8fd250a5c 100644
--- a/docs/api.rst
+++ b/docs/api.rst
@@ -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
diff --git a/hy/core/util.hy b/hy/core/util.hy
index 6a3f6ef9b..8f899cba9 100644
--- a/hy/core/util.hy
+++ b/hy/core/util.hy
@@ -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))
diff --git a/tests/native_tests/hy_misc.hy b/tests/native_tests/hy_misc.hy
index a75d63c20..022c54347 100644
--- a/tests/native_tests/hy_misc.hy
+++ b/tests/native_tests/hy_misc.hy
@@ -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)
@@ -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])