Repository: hylang/hy

Issue:
Off-by-1 error in tutorial comment
https://github.com/hylang/hy/blob/d175c5c7655b6f9343e5e27260d8db5e7b1e2865/docs/tutorial.rst#L77

There is overflow in comment :)


Discussion:
That's a pedantic complaint seeing as Python integers are arbitrary-size anyway, but I see your point. This was my line and I should know better.
> That's a pedantic complaint seeing as Python integers are arbitrary-size anyway, but I see your point. This was my line and I should know better.

Nah, I just nerding here 🤓. Example will loose its simplicity if will be changed.

Resolving patch:
diff --git a/hy/cmdline.py b/hy/cmdline.py
--- a/hy/cmdline.py
+++ b/hy/cmdline.py
@@ -721,44 +721,27 @@ def hy_main():
 
 def hyc_main():
     parser = argparse.ArgumentParser(prog="hyc")
-    parser.add_argument(
-        "files",
-        metavar="FILE",
-        nargs="*",
-        help=("File(s) to compile (use STDIN if only" ' "-" or nothing is provided)'),
-    )
+    parser.add_argument("files", metavar="FILE", nargs="+", help="File(s) to compile")
     parser.add_argument("-v", action="version", version=VERSION)
 
     options = parser.parse_args(sys.argv[1:])
 
     rv = 0
-    if len(options.files) == 0 or (len(options.files) == 1 and options.files[0] == "-"):
-        while True:
-            filename = sys.stdin.readline()
-            if not filename:
-                break
-            filename = filename.rstrip("\n")
-            set_path(filename)
-            try:
-                py_compile.compile(filename, doraise=True)
-            except py_compile.PyCompileError as error:
-                rv = 1
-                sys.stderr.write("%s\n" % error.msg)
-            except OSError as error:
-                rv = 1
-                sys.stderr.write("%s\n" % error)
-            sys.path.pop(0)
-    else:
-        for filename in options.files:
-            set_path(filename)
-            try:
-                print("Compiling %s" % filename)
-                py_compile.compile(filename, doraise=True)
-            except py_compile.PyCompileError as error:
-                # return value to indicate at least one failure
-                rv = 1
-                sys.stderr.write("%s\n" % error.msg)
-            sys.path.pop(0)
+    for filename in options.files:
+        set_path(filename)
+        try:
+            print(
+                "Compiling {!r} --> {!r}".format(
+                    filename, importlib.util.cache_from_source(filename)
+                ),
+                file=sys.stderr,
+            )
+            py_compile.compile(filename, doraise=True)
+        except py_compile.PyCompileError as error:
+            # return value to indicate at least one failure
+            rv = 1
+            print(error.msg, file=sys.stderr)
+        sys.path.pop(0)
     return rv
 
 


Test patch:
diff --git a/tests/test_bin.py b/tests/test_bin.py
--- a/tests/test_bin.py
+++ b/tests/test_bin.py
@@ -341,18 +341,12 @@ def test_file_with_args():
 
 
 def test_hyc():
-    _, err = run_cmd("hyc", expect=0)
-    assert err == ""
-
-    _, err = run_cmd("hyc -", expect=0)
-    assert err == ""
-
     output, _ = run_cmd("hyc -h")
     assert "usage" in output
 
     path = "tests/resources/argparse_ex.hy"
-    output, _ = run_cmd("hyc " + path)
-    assert "Compiling" in output
+    _, err = run_cmd("hyc " + path)
+    assert "Compiling" in err
     assert os.path.exists(cache_from_source(path))
     rm(cache_from_source(path))